2

I'm trying to multiply fractions in solidity. Does anyone know of a library or standard contract that provides overflow protection?

I'm assuming that I would have to make the decimal into a fraction first?

2 Answers 2

2

https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol

This is the standard library for safe math functions. Also, another option instead of decimals is just to multiply everything by a big number.

0

If you want to do something like

1 ether * 0.5

You can check out DS-Math.

Where you can do something like this

wmul(1, 0.5);

Or to be more precise

wmul(1000000000000000000, 500000000000000000); //1 ETH * 0.5

It seems to work fine but be careful because right now the project is not that popular compared to SafeMath...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.