October 05, 2001
Python vs Javascript
Today's technical problem involves rounding floating point numbers in different programming languages. I've converted some code from Javascript to Python and am getting inconsistent results. The original Javascript is;
var lat = delta * (360/TWOPI);
// lat is munged about and eventually contains -3.0
lat = (Math.round(lat/2 - 1) * 2) + 1;
WScript.echo(lat) // outputs '-3'
And my Python version is;
>>> lat = -3.0
>>> latty = (round((lat/2) - 1) * 2) + 1
>>> latty
-5.0
So we have a rounding issue. Any suggestions? Anyone?
Posted by Andy Todd at October 05, 2001 04:13 PM
Comments