займ на карту онлайн кредит банк

Usage of Float Numbers in Smart contract

0

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 !

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.

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?