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?
Thank you for your answers!
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?
Thank you for your answers!
According to the docs: http://solidity.readthedocs.io/en/latest/types.html#fixed-point-numbers
Fixed point numbers are not fully supported by Solidity yet. They can be declared, but cannot be assigned to or from.
So to answer your question, they exist, but you can't use them yet.
When they become supported, you'll be able to use them to represent a number with a fixed number of decimal places.
A side note, I found this question, because I need to store a dollar value in my contract. It seems as though I will either have to store cents as a uint or just use a string... probably going with cents, so that I can easily perform operations... Not sure if that helps you.
There are no fixed
and ufixed
data types in Solidity.
Data types in Solidity are categorised into Value types and Reference types.
Value types includes bool
, int
, uint
, byte
, etc. byte
is a fixed-sized byte array.
Reference types includes Arrays, Structs, Mappings.
To know about these in detail, please go through this Solidity Types documentation.
Solidity v0.4.24 (solc-js)
I believe the fixed and ufixed are upcoming types. fixed and unsigned fixed are most certainly float with a defined decimal part. uint256x75 with a 75 bits decimal part. I would believe that it means that the integer part become 181 bits.
The following code
int256 constant public data = 200 / 3;
generates the error below at compile time:
TypeError: Type rational_const 200 / 3 is not implicitly convertible to expected type uint256. Try converting to type ufixed256x75 or use an explicit conversion.
Other error encountered:
UnimplementedFeatureError: Not yet implemented - FixedPointType.
More about this: https://github.com/ethereum/solidity/issues/3200