The function responsible for making the conversion is the parseFloat and is not associated with any object. Number.parseFloat
is the same used by parseFloat
. To ECMA determines how the algorithm works, but the implementation can be different depending on the Engine Javascript.
Specification (Translation) of the algorithm
The function parseFloat
produces a numerical value dictated by the interpretation of the content of the string literal decimal.
When the function parseFloat
is called with an argument string, the following steps are taken:
Let inputString was toString
ReturnIfAbrupt
note: The term abrupt (sudden) conclusion refers to any conclusion with the type value other than normal
Let trimmedString be a substring of inputString consisting of the leftmost unit of code other than Strwhitespacechar and all code units to the right of the code unit. (In other words, remove whitespace). If inputString does not contain any kind of code unit, let trimmedString be an empty string.
If not even trimmedString nor any prefix of trimmedString satisfies the syntax of Strdecimalliteral, return Nan
Let numberString be the longest prefix of trimmedString, which may be trimmedString which satisfies the syntax of a Strdecimalliteral
Let mathFloat be mv of numberString
If mathFloat=0, then
a. If the first unit of trimmedString is "-", returne -0
b. Return +0
Return the numeric value to mathFloat
NOTE: parseFloat
perhaps only interprets the main part of the string as a numerical value; it ignores any unit of code that cannot be interpreted as part of the notation of a decimal literal, and no indication is given when any unit of code has been ignored.
The algorithm specifies the call of other native functions in its stream, such as trim()
for example.
To specification Ecmascript defines the exact algorithm used by
parseFloat
, whose exact implementation depends on the engine– Isac