[Ethereum] Usage of Float Numbers in Smart contract


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 !

Best Answer

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?

Related Topic