On Dec 14, 11:50*am, "BartC" <(EMail Removed)> wrote:
> "glen herrmannsfeldt" <(EMail Removed)> wrote in message
>
> news:kae67t$isr$(EMail Removed)...
>
> > BartC <(EMail Removed)> wrote:
> >> Because integers don't do fractions very well. Not without using special
> >> methods, at which point it becomes easier to just use floating point.
> >> But if you then have to calculate 15.9% tax on $53.49, it's a lot
> >> easier with floating point.
>
> > Take 5349 (cents) multiply by 159 and then divide by 1000 to get the
> > truncated tax in cents. But with tax, you have to watch the rounding.
> > If you want the rounded value, add 500 before dividing by 1000.
>
> OK, by using 'special methods' as I mentioned. You've now also introduced
> the arbitrary figures 10 (10*15.9), 500 and 1000, and presumably need to
> impose some arbitrary convention as to how percentage values are going tobe
> represented in the program (I guess you can't just have 15.9 or 0.159).
>
> At this level of program, just using floating point is a lot easier! You
> just need to round to a cent at every stage, taking care when values are
> negative; one little function.
>
> > With floating point, the intermediate values might be rounded.
>
> Do you have a calculation where that rounding (which will be to the
> loworder bits of the representation) will actually give a different result
> to doing the whole thing with integers? (And with ordinary amounts that are
> likely to be encountered.)
>
> > Multiply be the value with four decimal places, after moving the decimal
> > point to the right four places, then divide by 10000. Not hard at all.
>
> No. Waste of time inventing floating point, really!
and rather horrid and easy to get wrong floating point! Fixed point is
just nasty leave it to the embedded programmers.
