```
iex(4)> Float.parse "9999999999999999"
{1.0e16, ""}
```

So if I want to get `9999999999999999`

, what should I do?

```
iex(4)> Float.parse "9999999999999999"
{1.0e16, ""}
```

So if I want to get `9999999999999999`

, what should I do?

Not use Floats. Floats are just an approximation, not a correct number. Which is why one should never use floats for money values. You could either use integers or decimal numbers.

1 Like

Thanks, I found a similar comment here https://github.com/phoenixframework/phoenix/issues/1347#issuecomment-155404541, will try decimal.

Why not `Integer`

?

`Decimal`

s have some computational and memory overhead, because they are structs that consist of three values: The hole number part, the fraction part and the precision. For all computations made on `Decimal`

they have to be weighed against each other.

If you do not expect fractions to occur, use an `Integer`

, if you expect fractions to occur but you do also know that they will always have the same precision, use a tagged `Integer`

(eg. `{:money, 1000}`

for 10$) and write some functions to use it.

3 Likes

You can find a number of good articles on the net describing floats and the problems with them. For example:

https://docs.python.org/2/tutorial/floatingpoint.html

http://floating-point-gui.de/

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

3 Likes