{ "id": "115665", "key": "TIMOB-14194", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2018-07-11T20:39:45.000+0000", "created": "2013-06-07T09:13:03.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [ { "id": "14162", "description": "Release 3.1.0", "name": "Release 3.1.0", "archived": true, "released": true, "releaseDate": "2013-04-16" }, { "id": "14982", "description": "Release 3.2.0", "name": "Release 3.2.0", "archived": false, "released": true, "releaseDate": "2013-12-19" } ], "issuelinks": [ { "id": "29524", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "115773", "key": "AC-2216", "fields": { "summary": "Bug of Paypal iOS Titanium module dealing with some floating numbers", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2018-07-11T20:39:45.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "*Problem*\r\nThe output of floating point values in Titanium differ from browser JavaScript parsers such as [jsbin.com|http://www.jsbin.com/].\r\n\r\nFor example, Ti.API.info(94.1) displays 94.0999999\r\n\r\nOn jsbin.com the output of alert(94.1) is 94.1\r\n\r\n*Note*\r\nSince 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.\r\n\r\n*Test case*\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor : \"#FFF\"\r\n});\r\n\r\nfor (var i = 0; i < 50; i++)\r\n\tTi.API.info(94.1);\r\n\r\nwin.open();\r\n{code}\r\n\r\n*Extended test case*\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor : \"#FFF\"\r\n});\r\n\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.1);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.2);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.3);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.4);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.5);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.6);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.7);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.8);\r\nfor (var i = 0; i < 1000; i++)\r\n\tTi.API.info(i + 0.9);\r\n\r\nwin.open();\r\n{code}\r\n\r\n*Log - Unusual Titanium values*\r\n{code}\r\n[INFO] : 64.09999999999999\r\n[INFO] : 65.09999999999999\r\n[INFO] : 66.09999999999999\r\n[INFO] : 67.09999999999999\r\n[INFO] : 68.09999999999999\r\n[INFO] : 69.09999999999999\r\n...\r\n[INFO] : 70.09999999999999\r\n[INFO] : 71.09999999999999\r\n[INFO] : 72.09999999999999\r\n[INFO] : 73.09999999999999\r\n[INFO] : 74.09999999999999\r\n[INFO] : 75.09999999999999\r\n[INFO] : 76.09999999999999\r\n[INFO] : 77.09999999999999\r\n[INFO] : 78.09999999999999\r\n[INFO] : 79.09999999999999\r\n[INFO] : 80.09999999999999\r\n[INFO] : 81.09999999999999\r\n[INFO] : 82.09999999999999\r\n[INFO] : 83.09999999999999\r\n[INFO] : 84.09999999999999\r\n[INFO] : 85.09999999999999\r\n[INFO] : 86.09999999999999\r\n[INFO] : 87.09999999999999\r\n[INFO] : 88.09999999999999\r\n[INFO] : 89.09999999999999\r\n[INFO] : 90.09999999999999\r\n[INFO] : 91.09999999999999\r\n[INFO] : 92.09999999999999\r\n[INFO] : 93.09999999999999\r\n[INFO] : 94.09999999999999\r\n[INFO] : 95.09999999999999\r\n[INFO] : 96.09999999999999\r\n[INFO] : 97.09999999999999\r\n[INFO] : 98.09999999999999\r\n[INFO] : 99.09999999999999\r\n...\r\n[INFO] : 8.199999999999999\r\n[INFO] : 9.199999999999999\r\n...\r\n[INFO] : 8.300000000000001\r\n[INFO] : 9.300000000000001\r\n...\r\n[INFO] : 64.40000000000001\r\n[INFO] : 65.40000000000001\r\n[INFO] : 66.40000000000001\r\n[INFO] : 67.40000000000001\r\n[INFO] : 68.40000000000001\r\n[INFO] : 69.40000000000001\r\n[INFO] : 70.40000000000001\r\n[INFO] : 71.40000000000001\r\n[INFO] : 72.40000000000001\r\n[INFO] : 73.40000000000001\r\n[INFO] : 74.40000000000001\r\n[INFO] : 75.40000000000001\r\n[INFO] : 76.40000000000001\r\n[INFO] : 77.40000000000001\r\n[INFO] : 78.40000000000001\r\n[INFO] : 79.40000000000001\r\n[INFO] : 80.40000000000001\r\n[INFO] : 81.40000000000001\r\n[INFO] : 82.40000000000001\r\n[INFO] : 83.40000000000001\r\n[INFO] : 84.40000000000001\r\n[INFO] : 85.40000000000001\r\n[INFO] : 86.40000000000001\r\n[INFO] : 87.40000000000001\r\n[INFO] : 88.40000000000001\r\n[INFO] : 89.40000000000001\r\n[INFO] : 90.40000000000001\r\n[INFO] : 91.40000000000001\r\n[INFO] : 92.40000000000001\r\n[INFO] : 93.40000000000001\r\n[INFO] : 94.40000000000001\r\n[INFO] : 95.40000000000001\r\n[INFO] : 96.40000000000001\r\n[INFO] : 97.40000000000001\r\n[INFO] : 98.40000000000001\r\n[INFO] : 99.40000000000001\r\n...\r\n[INFO] : 64.59999999999999\r\n[INFO] : 65.59999999999999\r\n[INFO] : 66.59999999999999\r\n[INFO] : 67.59999999999999\r\n[INFO] : 68.59999999999999\r\n[INFO] : 69.59999999999999\r\n[INFO] : 70.59999999999999\r\n[INFO] : 71.59999999999999\r\n[INFO] : 72.59999999999999\r\n[INFO] : 73.59999999999999\r\n[INFO] : 74.59999999999999\r\n[INFO] : 75.59999999999999\r\n[INFO] : 76.59999999999999\r\n[INFO] : 77.59999999999999\r\n[INFO] : 78.59999999999999\r\n[INFO] : 79.59999999999999\r\n[INFO] : 80.59999999999999\r\n[INFO] : 81.59999999999999\r\n[INFO] : 82.59999999999999\r\n[INFO] : 83.59999999999999\r\n[INFO] : 84.59999999999999\r\n[INFO] : 85.59999999999999\r\n[INFO] : 86.59999999999999\r\n[INFO] : 87.59999999999999\r\n[INFO] : 88.59999999999999\r\n[INFO] : 89.59999999999999\r\n[INFO] : 90.59999999999999\r\n[INFO] : 91.59999999999999\r\n[INFO] : 92.59999999999999\r\n[INFO] : 93.59999999999999\r\n[INFO] : 94.59999999999999\r\n[INFO] : 95.59999999999999\r\n[INFO] : 96.59999999999999\r\n[INFO] : 97.59999999999999\r\n[INFO] : 98.59999999999999\r\n[INFO] : 99.59999999999999\r\n...\r\n[INFO] : 8.800000000000001\r\n[INFO] : 9.800000000000001\r\n...\r\n[INFO] : 64.90000000000001\r\n[INFO] : 65.90000000000001\r\n[INFO] : 66.90000000000001\r\n[INFO] : 67.90000000000001\r\n[INFO] : 68.90000000000001\r\n[INFO] : 69.90000000000001\r\n[INFO] : 70.90000000000001\r\n[INFO] : 71.90000000000001\r\n[INFO] : 72.90000000000001\r\n[INFO] : 73.90000000000001\r\n[INFO] : 74.90000000000001\r\n[INFO] : 75.90000000000001\r\n[INFO] : 76.90000000000001\r\n[INFO] : 77.90000000000001\r\n[INFO] : 78.90000000000001\r\n[INFO] : 79.90000000000001\r\n[INFO] : 80.90000000000001\r\n[INFO] : 81.90000000000001\r\n[INFO] : 82.90000000000001\r\n[INFO] : 83.90000000000001\r\n[INFO] : 84.90000000000001\r\n[INFO] : 85.90000000000001\r\n[INFO] : 86.90000000000001\r\n[INFO] : 87.90000000000001\r\n[INFO] : 88.90000000000001\r\n[INFO] : 89.90000000000001\r\n[INFO] : 90.90000000000001\r\n[INFO] : 91.90000000000001\r\n[INFO] : 92.90000000000001\r\n[INFO] : 93.90000000000001\r\n[INFO] : 94.90000000000001\r\n[INFO] : 95.90000000000001\r\n[INFO] : 96.90000000000001\r\n[INFO] : 97.90000000000001\r\n[INFO] : 98.90000000000001\r\n[INFO] : 99.90000000000001\r\n{code}", "attachment": [ { "id": "39572", "filename": "螢幕快照 2013-06-07 下午05.11.43.png", "author": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-07T09:13:03.000+0000", "size": 64672, "mimeType": "image/png" }, { "id": "39576", "filename": "螢幕快照 2013-06-07 下午06.19.37.png", "author": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-07T10:20:39.000+0000", "size": 24811, "mimeType": "image/png" } ], "flagged": false, "summary": "TiAPI: Problem with floating point numbers in Titanium", "creator": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Ti SDK 3.0 GA, 3.1 GA, 3.2 CI", "comment": { "comments": [ { "id": "257428", "author": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Tested and confirmed with iOS 6 simulator, Ti SDK 3.1 GA and 3.2 CI.", "updateAuthor": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-12T19:38:19.000+0000", "updated": "2013-06-12T19:38:19.000+0000" }, { "id": "257470", "author": { "name": "clathrop", "key": "clathrop", "displayName": "Carter Lathrop", "active": true, "timeZone": "America/Los_Angeles" }, "updateAuthor": { "name": "clathrop", "key": "clathrop", "displayName": "Carter Lathrop", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-12T21:30:46.000+0000", "updated": "2013-06-12T21:31:19.000+0000" }, { "id": "257540", "author": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Yes, it only in iOS, and I have fixed it by modifying the module.\r\nDetail:http://stackoverflow.com/questions/16981033/bug-of-using-floating-number-in-titanium-sdk\r\nThanks all.", "updateAuthor": { "name": "calvin@ecthk", "key": "calvin@ecthk", "displayName": "Calvin Chan", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-13T01:45:38.000+0000", "updated": "2013-06-13T01:45:38.000+0000" }, { "id": "280279", "author": { "name": "sfeather", "key": "sfeather", "displayName": "Stephen Feather", "active": true, "timeZone": "America/New_York" }, "body": "Calvin,\r\n\r\nHave you submitted a PR for your fix?", "updateAuthor": { "name": "sfeather", "key": "sfeather", "displayName": "Stephen Feather", "active": true, "timeZone": "America/New_York" }, "created": "2013-11-20T01:18:06.000+0000", "updated": "2013-11-20T01:18:06.000+0000" }, { "id": "439138", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Marking as Invalid an closing. This is just how floating point numbers work. If you need to represent dollar amounts or specific decimal values, then you need to handle that in a different way. The linked stack overflow post and answer go directly to that.\r\n\r\nThere are libraries intended to handle precisely this use case: \r\n- https://github.com/dtrebbien/BigDecimal.js\r\n- https://github.com/MikeMcl/decimal.js/\r\n- http://mathjs.org/docs/datatypes/bignumbers.html\r\n\r\nIt's possible that someday this support will make it into a future JS spec, as V8 has just added BigInts: https://developers.google.com/web/updates/2018/05/bigint\r\n", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2018-07-11T20:39:45.000+0000", "updated": "2018-07-11T20:39:45.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }