Project: titanium
Issue TIMOB-14194: TiAPI: Problem with floating point numbers in Titanium
*Problem* The output of floating point values in Titanium differ from browser JavaScript parsers such as [jsbin.com|http://www.jsbin.com/]. For example, Ti.API.info(94.1) displays 94.0999999 On jsbin.com the output of alert(94.1) is 94.1 *Note* Since I have to input floating number for some modules, I must use floating number solution. I can't use a string method. I have also tried parseFloat(x.toFixed(1)), Math.round(x*10)/10 etc. The output was the same. *Test case* {code:javascript} var win = Ti.UI.createWindow({ backgroundColor : "#FFF" }); for (var i = 0; i < 50; i++)	Ti.API.info(94.1); win.open(); {code} *Extended test case* {code:javascript} var win = Ti.UI.createWindow({	backgroundColor : "#FFF" }); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.1); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.2); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.3); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.4); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.5); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.6); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.7); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.8); for (var i = 0; i < 1000; i++)	Ti.API.info(i + 0.9); win.open(); {code} *Log - Unusual Titanium values* {code} [INFO] : 64.09999999999999 [INFO] : 65.09999999999999 [INFO] : 66.09999999999999 [INFO] : 67.09999999999999 [INFO] : 68.09999999999999 [INFO] : 69.09999999999999 ... [INFO] : 70.09999999999999 [INFO] : 71.09999999999999 [INFO] : 72.09999999999999 [INFO] : 73.09999999999999 [INFO] : 74.09999999999999 [INFO] : 75.09999999999999 [INFO] : 76.09999999999999 [INFO] : 77.09999999999999 [INFO] : 78.09999999999999 [INFO] : 79.09999999999999 [INFO] : 80.09999999999999 [INFO] : 81.09999999999999 [INFO] : 82.09999999999999 [INFO] : 83.09999999999999 [INFO] : 84.09999999999999 [INFO] : 85.09999999999999 [INFO] : 86.09999999999999 [INFO] : 87.09999999999999 [INFO] : 88.09999999999999 [INFO] : 89.09999999999999 [INFO] : 90.09999999999999 [INFO] : 91.09999999999999 [INFO] : 92.09999999999999 [INFO] : 93.09999999999999 [INFO] : 94.09999999999999 [INFO] : 95.09999999999999 [INFO] : 96.09999999999999 [INFO] : 97.09999999999999 [INFO] : 98.09999999999999 [INFO] : 99.09999999999999 ... [INFO] : 8.199999999999999 [INFO] : 9.199999999999999 ... [INFO] : 8.300000000000001 [INFO] : 9.300000000000001 ... [INFO] : 64.40000000000001 [INFO] : 65.40000000000001 [INFO] : 66.40000000000001 [INFO] : 67.40000000000001 [INFO] : 68.40000000000001 [INFO] : 69.40000000000001 [INFO] : 70.40000000000001 [INFO] : 71.40000000000001 [INFO] : 72.40000000000001 [INFO] : 73.40000000000001 [INFO] : 74.40000000000001 [INFO] : 75.40000000000001 [INFO] : 76.40000000000001 [INFO] : 77.40000000000001 [INFO] : 78.40000000000001 [INFO] : 79.40000000000001 [INFO] : 80.40000000000001 [INFO] : 81.40000000000001 [INFO] : 82.40000000000001 [INFO] : 83.40000000000001 [INFO] : 84.40000000000001 [INFO] : 85.40000000000001 [INFO] : 86.40000000000001 [INFO] : 87.40000000000001 [INFO] : 88.40000000000001 [INFO] : 89.40000000000001 [INFO] : 90.40000000000001 [INFO] : 91.40000000000001 [INFO] : 92.40000000000001 [INFO] : 93.40000000000001 [INFO] : 94.40000000000001 [INFO] : 95.40000000000001 [INFO] : 96.40000000000001 [INFO] : 97.40000000000001 [INFO] : 98.40000000000001 [INFO] : 99.40000000000001 ... [INFO] : 64.59999999999999 [INFO] : 65.59999999999999 [INFO] : 66.59999999999999 [INFO] : 67.59999999999999 [INFO] : 68.59999999999999 [INFO] : 69.59999999999999 [INFO] : 70.59999999999999 [INFO] : 71.59999999999999 [INFO] : 72.59999999999999 [INFO] : 73.59999999999999 [INFO] : 74.59999999999999 [INFO] : 75.59999999999999 [INFO] : 76.59999999999999 [INFO] : 77.59999999999999 [INFO] : 78.59999999999999 [INFO] : 79.59999999999999 [INFO] : 80.59999999999999 [INFO] : 81.59999999999999 [INFO] : 82.59999999999999 [INFO] : 83.59999999999999 [INFO] : 84.59999999999999 [INFO] : 85.59999999999999 [INFO] : 86.59999999999999 [INFO] : 87.59999999999999 [INFO] : 88.59999999999999 [INFO] : 89.59999999999999 [INFO] : 90.59999999999999 [INFO] : 91.59999999999999 [INFO] : 92.59999999999999 [INFO] : 93.59999999999999 [INFO] : 94.59999999999999 [INFO] : 95.59999999999999 [INFO] : 96.59999999999999 [INFO] : 97.59999999999999 [INFO] : 98.59999999999999 [INFO] : 99.59999999999999 ... [INFO] : 8.800000000000001 [INFO] : 9.800000000000001 ... [INFO] : 64.90000000000001 [INFO] : 65.90000000000001 [INFO] : 66.90000000000001 [INFO] : 67.90000000000001 [INFO] : 68.90000000000001 [INFO] : 69.90000000000001 [INFO] : 70.90000000000001 [INFO] : 71.90000000000001 [INFO] : 72.90000000000001 [INFO] : 73.90000000000001 [INFO] : 74.90000000000001 [INFO] : 75.90000000000001 [INFO] : 76.90000000000001 [INFO] : 77.90000000000001 [INFO] : 78.90000000000001 [INFO] : 79.90000000000001 [INFO] : 80.90000000000001 [INFO] : 81.90000000000001 [INFO] : 82.90000000000001 [INFO] : 83.90000000000001 [INFO] : 84.90000000000001 [INFO] : 85.90000000000001 [INFO] : 86.90000000000001 [INFO] : 87.90000000000001 [INFO] : 88.90000000000001 [INFO] : 89.90000000000001 [INFO] : 90.90000000000001 [INFO] : 91.90000000000001 [INFO] : 92.90000000000001 [INFO] : 93.90000000000001 [INFO] : 94.90000000000001 [INFO] : 95.90000000000001 [INFO] : 96.90000000000001 [INFO] : 97.90000000000001 [INFO] : 98.90000000000001 [INFO] : 99.90000000000001 {code}
Story points: 5