Math in Solidity is done entirely using fixed-point. For ether, there's no need to use fractional values - all values are represented in wei, which is the smallest unit of ether.
If you want to send 0.5 ether, you can instead specify your literal as "500 finney", which will be converted into wei:
msg.sender.send(500 finney);
or:
msg.sender.send(1 ether / 2);
which are both exactly equivalent to:
msg.sender.send(500000000000000000);
If you want to multiply a value by a fraction (eg, 2/3), first multiply by the numerator, then divide by the denominator:
value = (value * 2) / 3;
It's worth noting, too, that floating point for financial math is a terrible idea - it introduces rounding errors that easily lead to lost money.
In practice, the call stack imposes a limitation in current implementations.
The following contract will face a 'Stack too deep' compiler error.
pragma solidity ^0.4.3;
contract Test {
function getData() constant returns (bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32) {
return ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o");
}
}
Browser Solidity:
https://ethereum.github.io/browser-solidity/#gist=ac9812a045a41fd4168f2e352732962d
Gist URL:
https://gist.github.com/anonymous/ac9812a045a41fd4168f2e352732962d
Best Answer
When I try to run this code on remix it gave
UnimplementedFeatureError: Not yet implemented - FixedPointType.
Which you can see here This is not possible to useuint(3/30)
as you are doing. Casting of any floating point using uint is not acceptable.The Fixed Point are not yet unuseable in solidity as it documentation says:
You may solve this problem by.
1)You may use divi function from ABDK Math 64.64 library. It divides one integer by another and returns the result as 64.64-bit fixed point number.
2)You can multiply the number by
10^n
. Where 'n' is number of decimals in your return value.EDIT:
Well the uint shouldn't return anything at all instead it must give an error as mentioned above.