44k views

### 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 ...
• 782
13k views

### 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 ...
• 537
40k views

### 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.
22k views

### 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 = ...
• 273
9k views

### 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? ...
2k views

### 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 ...
• 163
5k views

### 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: ...
• 683
2k views

### 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 ...
• 1,154
1k views

### 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 ?
• 2,472
3k views

### 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....
• 101
2k views

### 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 ...
• 433
1 vote
746 views

### Why does division still truncate even though readthedocs.io says it does not?

According to readthedocs.io: "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, ...
1 vote
1k views

### 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 ...
• 4,330
2k views

### 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 ...
• 342