3

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!

  • 2
    do you mean fixed size types or fixed point types? – Badr Bellaj Jul 14 '17 at 8:04
  • I am not sure what is the difference between those. Can you give an example for both? – branko terzic Jul 14 '17 at 10:29
  • Ok, now I know what is the diff. But, my qustion is: does fiexd and ufixed exist as a data types in Solidity and if does, than what are they used for? – branko terzic Jul 14 '17 at 11:20
  • Solidity still does not have fixed point numbers fully functional, though there are libraries for them, such as ABDK Math 64.64. This library operates with binary fixed point numbers (64 binary digits after dot) and has all basic math operations. – Mikhail Vladimirov Apr 11 at 11:04
7

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.

  • 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
4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.