5

I'm having an issue where send 0.1 or 1.1 is saved as 0 and 1 in my contract's storage.

Does anyone knows how to properly pass decimals ?

6

Floating-point or fixed-point decimals have not yet been implemented in Solidity.

If you want, for example, 10 decimal places of precision you can just multiply all inputs by 10^10.

In this case, you would input 0.1e10 or 1.1e10 respectively, then when you fetch them you can just divide by 1e10

  • What about negative int -1 ? – jayD Feb 17 '16 at 1:34
  • negatives should still work, just use int instead of uint – Tjaden Hess Feb 17 '16 at 1:35
  • Wouldn't dividing by 1e10 just chop off everything that's past the decimal anyway? – Jossie Calderon Jun 15 '17 at 7:59
  • You would only do the division when displaying the value to the end user, in which case you would be using a language with floating point support like JS – Tjaden Hess Jun 15 '17 at 10:07

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.