I am trying to store a decimal number in a smart contract struct which represent the price of an item.

The field in the struct is uint and I want to store values like 0.001 which is the cost in ether. When I read the cost value I get a BigNumber similar to this:

BigNumber { s: 1, e: 0, c: [ 0 ] }

How can I read the value 0.0001 from the frontend?


ufixed datatypes are not supported yet. See the warning notice in here.

But you can save the number insolidity multiplied by 10**decimals, where decimals is the number of decimal points you want to use. When you retrieve the value in at the front end you just need to divide the returned number by 10**decimals.

I hope this helps.

| improve this answer | |

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.