number-parse-float.js 560 B

1234567891011121314
  1. var global = require('../internals/global');
  2. var trim = require('../internals/string-trim').trim;
  3. var whitespaces = require('../internals/whitespaces');
  4. var $parseFloat = global.parseFloat;
  5. var FORCED = 1 / $parseFloat(whitespaces + '-0') !== -Infinity;
  6. // `parseFloat` method
  7. // https://tc39.es/ecma262/#sec-parsefloat-string
  8. module.exports = FORCED ? function parseFloat(string) {
  9. var trimmedString = trim(String(string));
  10. var result = $parseFloat(trimmedString);
  11. return result === 0 && trimmedString.charAt(0) == '-' ? -0 : result;
  12. } : $parseFloat;