CodePudding user response:
The parseFloat (STR) + 0.01CodePudding user response:
it's nice to give me free...If you this is the version number
The function updateVarsion (version: string, index=0) : string {
/* * separate array */
Const arr=version. The split (')
/* * * need to manipulate the index number/
Const updateIndex=arr. Length - (1 + index)
/* * next value */
Const nextVersion=Number (arr) [updateIndex] + 1
/* * the maximum value at all levels, beyond the upgrade: this is the opposite, the last in the former definition; You don't need the associated code deletes */
Const maxVersion=[10, 10, 100]
//the current node overrun, zero, upgrade
If (nextVersion & gt; MaxVersion [index]) {
Arr [updateIndex]='0'
Return updateVarsion (arr. Join ('), the index + 1)
}
Arr=[updateIndex] String (nextVersion)
Return arr. Join (')
}
//at the end of the term appreciation=& gt; 1.0.10
The console. The log (updateVarsion (' 1.0.9))
//to the middle item=& gt; 1.1.0
The console. The log (updateVarsion (' 1.0.10))
//upgraded by item at the end of the first item=& gt; 2.0.0
The console. The log (updateVarsion (' 1.10.10))
//direct manipulation among items=& gt; 1.2.10
The console. The log (updateVarsion (' 1.1.10 ', 1))
CodePudding user response:
The parseFloat ()
ParseFloat () method and the parseInt () method to deal with in a similar way, starting from the position 0 check each character, until you find the first valid character, then put the character string into an integer before,
, however, for this method, first appeared in the decimal point is valid characters, if there are two decimal point, the second decimal point will be regarded as invalid, the parseFloat () to convert the characters of the decimal point before the number, which means that the string "11.22.33" will be parsed into 11.22,
Use the parseFloat () method of another difference is that the string must be expressed as a decimal floating point Numbers, rather than using octal or hexadecimal, this method ignores leading 0, so will be parsed octal number 0102 to 102, the hexadecimal number 0 xa, this method returns NaN, because in floating point Numbers, x is not a valid characters, (note: after test, specific browser implementation will return 0, rather than NaN,)
In addition, the parseFloat () method and no base model,
Below is use the parseFloat () method to some examples:
Var fNum4=parseFloat (" 11.22.33 ");