7

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!

branko terzic
  • 473
  • 4
  • 12

3 Answers3

11

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.

Nick Young
  • 226
  • 2
  • 3
  • A side note was helpful to me also, and in meantime I had plenty of experience dealing with similar problems. Tnx anyway. – branko terzic Oct 11 '17 at 20:00
3

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.

  • I am knew all of these. My question is what are fixed and ufixed ddata types used for, and I need some examples for these. – branko terzic Jul 18 '17 at 12:34
0

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

Cyril
  • 197
  • 1
  • 9