also this doesn't help, there are still errors in the accuracy. Isn't 
there a perfect way to do such calculations?<br><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div>
<div class="h5">Karsten Goen <<a href="mailto:karsten.goen@googlemail.com">karsten.goen@googlemail.com</a>> wrote:<br>
> hey all,<br>
> I got a problem with floats and calculations. I made an mini-application where<br>
> you get random questions with some science calculations in it<br>
> So the user can type in his result with the values given by random creation.<br>
> And the user value is compared against the computer value... the problem is<br>
> that the user input is only 2 numbers behind the '.' so like 1.42, 1.75<br>
><br>
> here is the example:<br>
> <a href="http://dpaste.com/hold/158698/" target="_blank">http://dpaste.com/hold/158698/</a><br>
><br>
> without decimal it would be very inaccurate. decimal is very accurate when I<br>
> have to compare d with users calculations from a,b,c,var.<br>
> But when I ask the user what is "a" the result gets inaccurate when calculating<br>
> with the same values given before (b,c,d,var).<br>
><br>
> Maybe anyone can help me with this problem, I don't want to generate for every<br>
> possible user input a single formula. And also it should be possible for a<br>
> computer, my calculator at home does the same and is much smaller and slower.<br>
<br>
</div></div>d = (a * b)/ (c * var)<br>
d = Decimal(d).quantize(Decimal('0.01'))<br>
<br>
By quantizing d, the above equality does not hold any longer. You've got<br>
to drop that line (your calculator doesn't quantize either).<br>
<br>
<br>
Stefan Krah<font color="#888888"><br>
</font></blockquote></div><br>