<div dir="ltr">In Python:-<div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><br></div><div><div>>>> 28 * 85 * 312 * 5 * (85.0 / 100)</div><div>3155880.0</div></div><div><br></div></blockquote>
In Erlang:-</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>16> 28 * 85 * 312 * 5 * 85 / 100.</div><div>3155880.0</div></div><div><br></div></blockquote>In Erlang (via rational Numbers): <a href="https://github.com/sdanzan/erlang-tools">https://github.com/sdanzan/erlang-tools</a></div>
<div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>15> rationals:mul(rationals:mul(rationals:mul(rationals:mul({28,1},{85,1}), {312,1}), {5,1}), {85,100}).</div><div>{3155880,1}</div>
</div><div><br></div></blockquote><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 27 November 2013 23:02, Alexander Alexeev <span dir="ltr"><<a href="mailto:mail@eax.me" target="_blank">mail@eax.me</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Here is a real world example. We are calculating a commission:<br>
<br>
28 x 85 x 312 x 5 / 0.85<br>
<br>
In this case decimal gives you a rounding error +/- 0.01 USD. With<br>
_any_ chosen precision. But if you are using something like Data.Ratio<br>
you'll get:<br>
<br>
28 x 85 x 312 x 5 / 0.85 =<br>
28 x 85 x 312 x 5 x 85 / 100 =<br>
exactly 4368000 USD<br>
<br>
See the difference?<br>
<div class="HOEnZb"><div class="h5"><br>
> >>Unfortunately, decimal does not solves all problems.<br>
><br>
> I do not want to be sarcastic, but it is really hard to divide 100<br>
> dollars between three guys,<br>
> give them all the same amount (100/3) and then say "Sorry, I need my<br>
> money back".<br>
> Do you think you will have 100 dollars then?<br>
><br>
> You need to decide what precision is right for you (specifically when<br>
> you ared dividing), how to correctly round and so on. There is a whole<br>
> mathematics about it.<br>
><br>
> You need to determine needed precision.<br>
> Sometimes the value 3.14 is good, but sometimes the value<br>
> 3,14159265358979323846 is not good enough...<br>
><br>
> Decimals do solve problems if you know needed precision.<br>
><br>
> In financials you need to calculate millions and billions with a<br>
> precision to cents.<br>
><br>
> And - for example - for US Debt ( <a href="http://www.usdebtclock.org/" target="_blank">http://www.usdebtclock.org/</a> ) you<br>
> need 16 digits (trillions) if you want to be accurate to cents right<br>
> now. :-) Imagine to express US Debt in Japanese Yen :-)<br>
><br>
> Regards,<br>
> Bob<br>
><br>
><br>
><br>
><br>
> 2013/11/27 Anthony Ramine <<a href="mailto:n.oxyde@gmail.com">n.oxyde@gmail.com</a>><br>
><br>
> > This looks like a bug in decimal though, this time.<br>
> ><br>
> > --<br>
> > Anthony Ramine<br>
> ><br>
> > Le 27 nov. 2013 à 14:37, Alexander Alexeev <<a href="mailto:mail@eax.me">mail@eax.me</a>> a écrit :<br>
> ><br>
> > > Unfortunately, decimal does not solves all problems.<br>
> ><br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> ><br>
<br>
<br>
</div></div><div class="im HOEnZb">--<br>
Best regards,<br>
Alexander Alexeev<br>
<a href="http://eax.me/" target="_blank">http://eax.me/</a><br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Iqbal Talaat Bhatti<br><br><span><span>"If we did all the things we are capable of doing, we would
literally astound ourselves." - Thomas Edison</span></span><br>
</div>