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?

GK1
  • 129
  • 2
  • 10

2 Answers2

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.

thefett
  • 3,873
  • 5
  • 26
  • 48
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...

CodingYourLife
  • 729
  • 1
  • 6
  • 18