I am not able to store and retrieve some values of Float types from smart contract. I am about to store the values of IP Address, Geo-location, Mac address etc.. which all are of float types. I know float types are not currently supported in solidity, is there any work around for the same !

  • 2
    You are storing IP addresses as floating points? That's a unique approach.
    – Jesbus
    Dec 4, 2018 at 18:09

5 Answers 5


Yes, float is currently not supported in solidity. But you can decimals for that.

And honestly for storing IP address, geolaoctaion in conventional techs like Java, Node, float doesn't seem to a good choice. Float , int is suited when you need to perform some mathematical operations. Else you should store them as string.

You can choose String or bytes32 depending on your choice. See User string or bytes 32?

  • 1
    I tried to store with String or bytes32 but the errr is : _Uncaught TypeError: Cannot read property 'length' of undefined at Object.ip.toString _
    – Aiswarya
    Jul 9, 2018 at 6:23
  • 1
    Where do you exactly get this error? Need to see the cod, hard to tell the issue without that. Be sure to use quoutes while dealing with strings. Jul 9, 2018 at 7:18

As others mentioned, a Float is not possible in solidity, or more precise, the EVM.

The obvious reason is that floats are, by nature, unpredictable, which would make the outcome of operations different over nodes. Which would lead to forks.

However, all examples you state have nothing to do with Floats:

  • IP-addresses are 32 (IPV4) or 128 (IPV6) bit numbers. They are just formatted weirdly. is just 2130706433
  • Geo- Locations, or pairs of LAT/LON, are decimals, really. Sometimes presented in base60 or base 12 (10"23'0 etc). LAT and LON may look like floats, but geo-locations have a precision built in by their standards: the more decimails you give, the more precise the point is. Depending on your implementation, you might need this precision up to centimeters or kilometers.
  • MAC-addresses are 48-bit numbers, similar to how IP-addresses work. They are, however, often presented in hexadecimal formats.

This is an often-made mistake. We hardly ever need to store floats. We hardly ever need to pass floats along. But we might have floats in a program when operating internally, but even this is not often necessary. In other words: when you think you need to deal with floats: think again: you quite probably don't want floats.


I assume that by float types you mean types that are able to store fraction numbers, such as 3.14. Floating point is quite common representation for such numbers, but for Ethereum/Solidity fixed point is considered more promising. Fixed point number of basically a simple fraction with fixed denominator, i.e. fraction x/N where N is a constant and x may vary.

Currently most common value for N is 1,000,000,000,000,000,000, i.e. 10^18, so fraction numbers are represented as integers, like this:

1.0 -> 1000000000000000000
0.5 -> 500000000000000000
3.14 -> 3140000000000000000

and so on. While Solidity still lacks native support for such numbers, libraries exists for them, such as DS Math.

Though, such representation is convenient for humans who are familiar with decimal numbers, but not for computers that use binary numbers.

You should probably take as look at ADBK Math 64.64 library. It operates with binary fixed point number having 64 binary digits after dot, i.e. denominator is 2^64 rather than 10^18.


you could multiply your float numbers by a factor that always converts them to integers. e.g if your float only has 2 decimal places, factor could be 100. This factor should be applied in your fronted before sending it to your smart contract. So if your user enters 14.32, you pass 1432 to your contract and store it, so when invoking this value from your contract it should be converted before displaying it or using it.

This factor should also be stored on your contract to avoid mistakes.

  • 1
    But here for example: IP Address is for that how can i use the conversion as said ? @Roberto C.
    – Aiswarya
    Jul 9, 2018 at 6:21
  • 1
    For IP addresses I believe storing as bytes or string makes more sense, depending if you want to pass them between contracts.
    – Roberto C.
    Jul 9, 2018 at 6:27
  • 1
    For IP address, maybe a uint8[4] would do the trick? It might be a little cheaper to store than bytes. Sep 14, 2018 at 13:41

Not all the data you cited are floating point data: IP and MAC ADDRESS are’t by definition, neither they are geolocation data if you fix the precision. One example of floating number is 3.25E+10, one example of fixed precision data is 12.34, IP number are four bytes long like 127.0.01 and the dot is simply a trick to read them easy, Macaddress is a truly address codified.

Anyway what you need is to represent your number as integer number, as you probably saw in tokens representation.

10.22000001 can easily represented as 1022000001 and so on

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.