File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const EMPTY = "";
1515
1616const literalRegExp = / ( \\ .) | ( [ ' ] [ ^ ' ] * [ ' ] ? ) | ( [ " ] [ ^ " ] * [ " ] ? ) / g;
1717const trailingZerosRegExp = / ( \. (?: [ 0 - 9 ] * [ 1 - 9 ] ) ? ) 0 + $ / g;
18+ const trailingPointRegExp = / \. $ / ;
1819const commaRegExp = / \, / g;
1920
2021function setFormatLiterals ( formatOptions ) {
@@ -33,18 +34,15 @@ function setFormatLiterals(formatOptions) {
3334}
3435
3536function trimTrailingZeros ( value , lastZero ) {
36- let result ;
37+ let trimRegex ;
38+
3739 if ( lastZero === 0 ) {
38- result = value . replace ( trailingZerosRegExp , '$1' ) ;
40+ trimRegex = trailingZerosRegExp ;
3941 } else {
40- result = value . replace ( new RegExp ( `(\\.[0-9]{${ lastZero } }[1-9]*)0+$` , 'g' ) , '$1' ) ;
41- }
42-
43- if ( result . charAt ( result . length - 1 ) === POINT ) {
44- result = result . substr ( 0 , result . length - 1 ) ;
42+ trimRegex = new RegExp ( `(\\.[0-9]{${ lastZero } }[1-9]*)0+$` , 'g' ) ;
4543 }
4644
47- return result ;
45+ return value . replace ( trimRegex , '$1' ) . replace ( trailingPointRegExp , '' ) ;
4846}
4947
5048function roundNumber ( formatOptions ) {
You can’t perform that action at this time.
0 commit comments