Change parseFloat() to Number()

Number() is a bit less forgiving than parseFloat() and is more likely to generate NaN rather than some random number.  An audit of each case shows nowhere that parseFloat()’s features are needed.
This commit is contained in:
Neil Fraser
2019-07-31 18:26:14 -07:00
committed by Neil Fraser
parent 8916dbf75b
commit e77a9b7e81
32 changed files with 66 additions and 65 deletions

View File

@@ -443,7 +443,7 @@ FactoryUtils.getFieldsJs_ = function(block) {
case 'field_angle':
// Result: new Blockly.FieldAngle(90), 'ANGLE'
fields.push('new Blockly.FieldAngle(' +
parseFloat(block.getFieldValue('ANGLE')) + '), ' +
Number(block.getFieldValue('ANGLE')) + '), ' +
JSON.stringify(block.getFieldValue('FIELDNAME')));
break;
case 'field_checkbox':
@@ -536,17 +536,17 @@ FactoryUtils.getFieldsJson_ = function(block) {
var obj = {
type: block.type,
name: block.getFieldValue('FIELDNAME'),
value: parseFloat(block.getFieldValue('VALUE'))
value: Number(block.getFieldValue('VALUE'))
};
var min = parseFloat(block.getFieldValue('MIN'));
var min = Number(block.getFieldValue('MIN'));
if (min > -Infinity) {
obj.min = min;
}
var max = parseFloat(block.getFieldValue('MAX'));
var max = Number(block.getFieldValue('MAX'));
if (max < Infinity) {
obj.max = max;
}
var precision = parseFloat(block.getFieldValue('PRECISION'));
var precision = Number(block.getFieldValue('PRECISION'));
if (precision) {
obj.precision = precision;
}