I have a problem with my client side script without calculating the same values as my server side code:
For instance:
var x = (2.85 * .1); alert(x);
This gives the figure 0.28500000000000003
However, my server side code (C #) computes the numbers 0.285, which when rounded to 2 decimal places give 0.28
If I try to round 0.28500000000000003 to 2 decimal places, I get 0.29.
How do I get my Javascript to create a shape that matches my server code.
It looks like I need to go through 2 rounds of rounding - first, to remove trailing 3, and then round to the desired decimal places.
For instance:
var x = 0.2850000000003; x = parseFloat(x.toFixed(3)) x = x.toFixed(2) alert(x);
Is this the best workaround?
(This is a reformulation of the question that I opened and deleted earlier)
source share