0

I've seen some thread already however I haven't found anywhere a way of converting a string number to float number and maintaining the decimals.

ie

"27.546" to 27.546
  • "uint number and maintaining the decimals"? Seriously??? Do you understand the meaning of "int" in "uint"? – goodvibration Jan 5 at 17:43
  • you are right. String to float number. – spyrAlex Jan 5 at 17:48
  • Shift the decimal point position to the right and use integer arithmetic – Mad Jackal Jan 5 at 18:12
  • Thanks for the suggestion @MadJackal. Can you show a quick example? – spyrAlex Jan 5 at 18:16
  • There are no floating-point types in Solidity. You need to do all the floating-point arithmetic on the off-chain side (for example, in a web3.js script), and use only integers when you interact with the on-chain (i.e., when you pass input to contract functions). – goodvibration Jan 5 at 18:32

Your Answer

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

Browse other questions tagged or ask your own question.