A problem with rounding

159 Views Asked by At

Short version of the question: when rounded variable is used to calculate another variable, should I use rounded or unrounded value?

Longer version: say I have two calculations: a / b = c and c + d = e (for the sake of clarity, a, b and d are known to us). In order to make things readable for the user, I round c (never mind the rounding algorithm). Now, when calculating d, should I use rounded or unrounded c as the source variable?

When I use the rounded value, d is further from the "real" value.

When I use the unrounded value, d is not a derivative of c as seen on screen (because rounded value is seen on screen and unrounded is used).

What's your take on the subject? Which way would you do it?

In case it matters: I'm doing all these calculations in javascript. The precision is not hugely important.

1

There are 1 best solutions below

0
On BEST ANSWER

That really depends on the semantics of these values. For example, if you compute the prices of individual items in a shopping basket, and the also compute the sum, you'd want to compute the sum from the rounded values. Otherwise, the final amount on the invoice might not equal the sum of the individual amounts, which will get you into trouble with your users and in most countries also with the law...

In other cases, where the intermediate values have purely informational character - you'd probably want to continue the computation with the raw values, and only round for displaying purposes.