Re: Rounding error when converting from double to int




"Gordon Burditt" <gordonb.9dw2o@xxxxxxxxxxx> ha scritto nel messaggio
news:L4ednasuFM67lxrXnZ2dnUVZ_uSdnZ2d@xxxxxxxxxxxxxxxxxxxxxxxxx
Do your calculation that generates the fractions in integers. I'm
assuming here that negative numbers are not involved. For example,
if you have $9.51 (represented as 951 cents) and you need to take
8.875% of it (suppose it's a sales tax calculation), multiply 8.875%
by one million and get 88750. (This presumes that sales tax rates
are always multiples of 0.0001%). Be sure *NOT* to put 8.875% into
a double. Represent it as 88750 / 1000000, and treat numerator and


first of doing this division, from 8.875 -> 88750 is there one rounding?

I told you above *NOT* to put the percentage into a double in the first
place, so there is no rounding.

Is the above mean "8.875" have be to put, form input to one integer?

if for example we have 8.795% and it is rappresented in double like
8.79499999999999999

DO NOT put that value into a double.

the result afther the "->" will be 87949 of 87950?

The multiplication should be done in mathematics, not C.

"in mathematics" means using only unsigned types?



.



Relevant Pages

  • Re: Rounding error when converting from double to int
    ... if you have $9.51 (represented as 951 cents) and you need to take ... 8.875% of it (suppose it's a sales tax calculation), ... are always multiples of 0.0001%). ... from 8.875 -> 88750 is there one rounding? ...
    (comp.lang.c)
  • Re: Rounding error when converting from double to int
    ... if you have $9.51 (represented as 951 cents) and you need to take ... 8.875% of it (suppose it's a sales tax calculation), ... are always multiples of 0.0001%). ... so there is no rounding. ...
    (comp.lang.c)
  • Re: Kids math book recommendation?
    ... |Could anyone please recommend a good introduction to mathematics ... |The target audience is a first-grader who does things like fooling ... |around with his "multiples" homework and a number line, ... been to not even tell him that the concept of non-multiple numbers has ...
    (sci.math)
  • Re: sprintf rounding behavior
    ... first i guessed that this is an inherent problem due to the binary ... been no round-off errors at all, and this would place them exactly at the ... half way points when it comes to rounding. ... errors in originally calculating the odd multiples of .05. ...
    (comp.soft-sys.matlab)
  • Kids math book recommendation?
    ... Could anyone please recommend a good introduction to mathematics ... (not an arithmetic workbook) ... The target audience is a first-grader who does things like fooling ... around with his "multiples" homework and a number line, ...
    (sci.math)

Loading