Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.7.0
-
None
-
Lenovo ThinkPad Ultrabook, Intel Core i7-6500 CPU @2.50GHz (dual core), Windows 10, QT 5.7
-
8b7dbfe1e0c0d4b8d0984fb381f1a0bb6b566e76
Description
QML's internal javascript interpreter does not adhere to Number.toPrecision's specification, specifically in the instances when the number object whose toPrecision method is called is the object containing an integer value (such as 82, 34, 2, etc) and the precision value passed to the method is greater than the number of digits in the original number
Javascript's Number.toPrecision method(as documented here should return a string with a given number of significant digits. For instance, when the number is 42, and the precision is 3, then the result should be the string "42.0". However, the method currently produces "42", with no padding zeroes at the end. As mentioned above, this contradicts the specification listed above.
Example code is below:
// Simple function for demonstrating the error in Number.toPrecision public String testToPrecision() { var number = 42; console.log(number.toPrecision());//prints "42" to the console (which it should) console.log(number.toPrecision(1))//prints "40" to the console (once again, accurate) console.log(number.toPrecision(2))//prints "42" to the console (accurate, again) console.log(number.toPrecision(3))//prints "42" to the console, which is an error. //the function, once the precision supplied passes the number of digits in the source number, //should pad the source number with '0's. }
Attachments
For Gerrit Dashboard: QTBUG-55358 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
168543,5 | V4: Correctly format on Number.toPrecision(n) | 5.7 | qt/qtdeclarative | Status: MERGED | +2 | 0 |