# [erlang-questions] Maths Problem -> 2452.45*100. = 245244.99999999997

I-T <>
Wed Nov 27 21:22:18 CET 2013

```In Python:-

>>> 28 * 85 * 312 * 5 * (85.0 / 100)
3155880.0

In Erlang:-

16> 28 * 85 * 312 * 5 * 85 / 100.
3155880.0

In Erlang (via rational Numbers): https://github.com/sdanzan/erlang-tools

15> rationals:mul(rationals:mul(rationals:mul(rationals:mul({28,1},{85,1}),
{312,1}), {5,1}), {85,100}).
{3155880,1}

On 27 November 2013 23:02, Alexander Alexeev <> wrote:

> Here is a real world example. We are calculating a commission:
>
> 28 x 85 x 312 x 5 / 0.85
>
> In this case decimal gives you a rounding error +/- 0.01 USD. With
> _any_ chosen precision. But if you are using something like Data.Ratio
> you'll get:
>
> 28 x 85 x 312 x 5 / 0.85 =
> 28 x 85 x 312 x 5 x 85 / 100 =
> exactly 4368000 USD
>
> See the difference?
>
> > >>Unfortunately, decimal does not solves all problems.
> >
> > I do not want to be sarcastic, but it is really hard to divide 100
> > dollars between three guys,
> > give them all the same amount (100/3) and then say "Sorry, I need my
> > money back".
> > Do you think you will have 100 dollars then?
> >
> > You need to decide what precision is right for you (specifically when
> > you ared dividing), how to correctly round and so on. There is a whole
> >
> > You need to determine needed precision.
> > Sometimes the value 3.14 is good, but sometimes the value
> > 3,14159265358979323846 is not good enough...
> >
> > Decimals do solve problems if you know needed precision.
> >
> > In financials you need to calculate millions and billions with a
> > precision to cents.
> >
> > And - for example - for US Debt ( http://www.usdebtclock.org/ ) you
> > need 16 digits (trillions) if you want to be accurate to cents right
> > now. :-) Imagine to express US Debt in Japanese Yen :-)
> >
> > Regards,
> > Bob
> >
> >
> >
> >
> > 2013/11/27 Anthony Ramine <>
> >
> > > This looks like a bug in decimal though, this time.
> > >
> > > --
> > > Anthony Ramine
> > >
> > > Le 27 nov. 2013 à 14:37, Alexander Alexeev <> a écrit :
> > >
> > > > Unfortunately, decimal does not solves all problems.
> > >
> > > _______________________________________________
> > > erlang-questions mailing list
> > >
> > > http://erlang.org/mailman/listinfo/erlang-questions
> > >
>
>
> --
> Best regards,
> Alexander Alexeev
> http://eax.me/
> _______________________________________________
> erlang-questions mailing list
>
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Iqbal Talaat Bhatti

"If we did all the things we are capable of doing, we would literally
astound ourselves." - Thomas Edison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131128/18b3f8af/attachment.html>
```