Re: This calculation is just wrong / computer can't count!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



GT,

You are just being silly. Think of the float type like you would a
slide rule. It gives you the best answer it can with the precision
available. It can't be more accurate than the number of bits it has
to work with. It is up to you to pick a computational type on the
computer with the correct degree of precision. It is the programmer's
job to manage the rounding errors. That is you in this case.

The advantage of float is that it can give you an answer accurate to 6
and a half decimal digits over a huge scale. Whether the answer is
83333 with 38 zeros following it, or 38 zeros after the decimal point
then 83333, it is as correct as it can be given the amount of storage
which you invested in it.

The amount of storage matters when you start putting these things in a
database.

If your goal is to accurately compute the answer for numbers in a
known range such as adding up monetary amounts then floating point is
a bad choice since it doesn't advertise this sort of accuracy. It
only claims to deliver an approximate answer, but it can do so for
very very small and very very large quantities.

-GB

On Mon, 8 Oct 2007 10:53:26 +0100, "GT"
<ContactGT_remove_@xxxxxxxxxxx> wrote:

I expected the C++ basic data types to be able to handle simple maths
properly. Clearly it can only store digits to a certain number binary
places, therefore the trailing digit in a decimal conversion is unreliable
and 9/10 times mathematically *WRONG*. I expected there to be some logic
built in to the data type to take care of this. Would you buy a calculator
that gave wrong results? That is reality!

.



Relevant Pages

  • Re: Rounding info needed-A2k
    ... If you use a Number field, you have a floating point data type. ... This is really useful for handling enormous numbers or miniscule numbers (hundreds of zeros after the decimal point before the digits really start), but they are limited to around 15 significant digits Most fractional numbers cannot be stored precisely in this binary form, just as many numbers cannot be stored precisely in the decimal form without an infinite number of digits. ... Therefore you will need to use Roundwhen performing calcuations that write a value so the Currency field, so ensure the last 2 digits are stored as zeros. ... I also have a control on a form that is either visible or not based on comparing a simple check amount entry of 3145.54 to a sum of the payments, all entered as individual dollar, cents entries that eventually SHOULD total the check amount. ...
    (comp.databases.ms-access)
  • Re: Alternate solution to krx113
    ... when I was experiementing and creating the code, and never got rid of them. ... formatting printfwith a number before it, it will right justify it by that number MINUS the amount of digits %d contains. ... printf(" *");} else { ...
    (comp.lang.c)
  • New LottoGenius version - comments please.
    ... limit an amount of numbers inside any decade. ... Final Digits: matching final digits (all digits count, ... control the low/high numbers ratio within a combination. ... Sums: range of sums (selected numbers within the combination ...
    (rec.gambling.lottery)
  • Re: Enigma 1390 - Old to new
    ... pence, used to be divided into 20 ... I found that the amount ... digits of the fraction) include all the ... currency and converted to the new ...
    (rec.puzzles)
  • Re: Very OT: Economic Stimulus Package Date Question
    ... Last two digits, lowest first. ... Eligibility for the stimulus payment is subject to maximum income ... including the basic amount and the amount for ...
    (rec.food.cooking)