<div dir="ltr"><div>It must be some misunderstanding.</div><div><br></div><div>This is my result in Erlang:</div><div><br></div><div>28 * 85 * 312 * 5 / 0.85.<br></div><div><div>4.368e6</div></div><div><br></div><div>or</div>
<div><br></div><div><div>28 * 85 * 312 * 5 / (85 / 100).<br></div><div><div>4.368e6</div><div><br></div><div>or</div><div><br></div><div>28 * 85 * 312 * 5 / (85 * 0.01).<br></div><div>4.368e6</div><div><br></div></div><div>
or using "decimal":<br></div><div><br></div><div><div>decimal:divide( decimal:multiply(28,decimal:multiply(85,decimal:multiply(312,5))), decimal:divide(85,100) ).<br></div><div><div>{0,43680,2}</div></div><div>
<br></div></div><div><div>or</div></div><div><br></div><div><div>decimal:divide( decimal:multiply(28,decimal:multiply(85,decimal:multiply(312,5))), decimal:multiply(85,0.01) ).<br></div><div>{0,4368,3}</div></div><div>
<br>
</div><div>No problem anywhere. Correct?</div><div><br></div><div>Bob</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">2013/11/27 Alexander Alexeev <span dir="ltr"><<a href="mailto:mail@eax.me" target="_blank">mail@eax.me</a>></span><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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=""><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">--<br>
Best regards,<br>
Alexander Alexeev<br>
<a href="http://eax.me/" target="_blank">http://eax.me/</a><br>
</div><div class=""><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></div></div></div>