Linked Questions

46 votes
6 answers

How can I represent decimal values in Solidity?

I just started writing some solidity and I noticed that there are no decimal values such as double or float. What do you guys do when you need to return send to a wallet let's say 1.57 ether? Or when ...
sfrj's user avatar
  • 782
27 votes
6 answers

Can I square root in Solidity?

Is it possible to square root 50 or should I use 7.071067. I'm very new in programming and I also understand that it's possible in all other languages, but I'm not able to see where the limitations ...
Sileniced's user avatar
  • 537
30 votes
5 answers

How can I perform float type division in solidity?

How can I achieve proper division of two integers in solidity? Suppose I perform : 3/2 the solution provided is 1 and not 1.5 please help.
Vaibhav Tiwari's user avatar
27 votes
4 answers

Can't do any integer division

I'm building a new smart contract but really can't figure out how to perform integer division. I know that fixed point numbers haven't been implemented yet but it should be possible to perform 100/3 = ...
Hugo Moreau's user avatar
7 votes
3 answers

Solidity data types fixed and ufixed

Can somebody explain what are the fixed and ufixed data types in Solidity. Can you give me some examples? I expected that these are the representations of decimal numbers, but this is not a case? ...
branko terzic's user avatar
6 votes
4 answers

Handling decimals in somewhat complex math

I'm a bit lost on what to do with the following calculation. The problem is that decimals are being round up/down, which obviously doesn't give me the result I desire. int totalValue = 275000; int ...
Nick's user avatar
  • 163
12 votes
2 answers

Finding and Using Solidity Libraries (ie. Math functions)

How do I find and use any existing Solidity libraries like you might in Javascript? For example, Math functions: How do I implement the equivalent of Math.sqrt(x) in a solidity function? Related: ...
Bill LaPrise's user avatar
3 votes
2 answers

price conversion using chainlink ETHUSD price

I'm storing a product's USD value in contract. mapping (string => uint256) productUSD; For example, if it's $52 I'd store it as productUSD[_product] = 52; Now, when people paying in ETH, I want to ...
bbusdriver's user avatar
  • 1,154
6 votes
1 answer

Can you input decimals number in smart contract?

I'm having an issue where send 0.1 or 1.1 is saved as 0 and 1 in my contract's storage. Does anyone knows how to properly pass decimals ?
jayD's user avatar
  • 2,472
0 votes
2 answers

Decimal in Solidity [duplicate]

I'm new to solidity but I program in other languages, solidity looks a bit like javascript but recently I noticed a problem with solidity. it doesn't accept decimals and float numbers, like "0....
M4theuz's user avatar
  • 101
2 votes
1 answer

How to split funds in single send transaction

Scenario: Alice Account = 2 ETH Admin Account = 0 ETH Bob Account = 0 ETH Alice wants to send 1 ETH to Bob using my application. Application will charge 0.01 ETH as it's commission and will be ...
Gagan's user avatar
  • 433
1 vote
1 answer

Why does division still truncate even though says it does not?

According to "Division on integer literals used to truncate in earlier versions, but it will now convert into a rational number, i.e. 5 / 2 is not equal to 2, but to 2.5". Yet, ...
CreatedAMadman's user avatar
1 vote
1 answer

Solidity 'real' type and fixed point regimes

I'm sure I read somewhere that Solidity had a fixed point type 'real' of format 32byte.32byte, though the docs say Fixed Point numbers are still to come. Until it's implemented, is there any best ...
o0ragman0o's user avatar
  • 4,330
0 votes
2 answers

Storing Very Large Numbers in Solidity Beyond uint256

I'm working on a smart contract designed to facilitate swaps, and given that values in Solidity are expressed in wei, I encounter exceedingly large numbers. Even when using uint256, I've run into ...
Kuly14's user avatar
  • 342
2 votes
1 answer

Is it possible to have 0% buy fee on DEX and 5% fee on Sell DEX and also when token is transfer?

Token Tokenomics will be like this: Buy: 0% Sell/Transfer: 5% and 5% goes to charity address. This is the token contract: ...
Lloyd Ramos's user avatar

15 30 50 per page