Use toLocaleString to count decimal places consistently (#4124)

This commit is contained in:
mfallihee
2020-08-10 10:47:14 -07:00
committed by GitHub
parent a2f851cda6
commit 254fb60481
2 changed files with 2 additions and 3 deletions

View File

@@ -231,7 +231,7 @@ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) {
}
}
var precisionString = this.precision_.toString();
var precisionString = this.precision_.toLocaleString("en-US", {maximumFractionDigits: 20});
var decimalIndex = precisionString.indexOf('.');
if (decimalIndex == -1) {
// If the precision is 0 (float) allow any number of decimals,

View File

@@ -112,9 +112,8 @@ suite('Number Fields', function() {
{title: 'Float', json: {}, value: 123.456, expectedValue: 123.456},
{title: '0.01', json: {precision: .01}, value: 123.456,
expectedValue: 123.46},
// TODO(#4105): Un-skip after fixing bug.
{title: '1e-7', json: {precision: .0000001}, value: 123.00000456,
expectedValue: 123.0000046, skip: true},
expectedValue: 123.0000046},
{title: '0.5', json: {precision: .5}, value: 123.456,
expectedValue: 123.5},
{title: '1', json: {precision: 1}, value: 123.456,