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!

5
  • 2
    do you mean fixed size types or fixed point types?
    – Badr Bellaj
    Commented Jul 14, 2017 at 8:04
  • I am not sure what is the difference between those. Can you give an example for both? Commented Jul 14, 2017 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? Commented Jul 14, 2017 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. Commented Apr 11, 2019 at 11:04

3 Answers 3

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.

1
  • A side note was helpful to me also, and in meantime I had plenty of experience dealing with similar problems. Tnx anyway. Commented Oct 11, 2017 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.

1
  • 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. Commented Jul 18, 2017 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 and acknowledge you have read our privacy policy.

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