feat(number): trim extra trailing zeroes (#1768)
This commit is contained in:
1 parent
91bcde9859
commit
2c62b5bebe
3 files changed
+74
No files matched your search
@@ -4302,6 +4302,8 @@ function printNumber(rawNumber) {
|
||||
.replace(/^([\d.]+)e[+-]?0+$/, "$1")
|
||||
// Make sure numbers always start with a digit.
|
||||
.replace(/^\./, "0.")
|
||||
// Remove extraneous trailing decimal zeroes.
|
||||
.replace(/(\.\d+?)0+(?=e|$)/, "$1")
|
||||
// Remove trailing dot.
|
||||
.replace(/\.(?=e|$)/, "")
|
||||
);
|
||||
|
||||
@@ -65,6 +65,30 @@ function test5(): string {
|
||||
0.5e+00
|
||||
0.5e-0
|
||||
0.5e-00
|
||||
|
||||
1
|
||||
1.00500
|
||||
1.0
|
||||
1.5
|
||||
1.50
|
||||
0
|
||||
0.00500
|
||||
0.0
|
||||
0.0000
|
||||
.0
|
||||
500600.001230045000
|
||||
1.00500e60
|
||||
1.0e60
|
||||
0.00500e60
|
||||
0.0e60
|
||||
0.0000e60
|
||||
.0e60
|
||||
0.e60
|
||||
0e60
|
||||
500600.001230045000e60
|
||||
10
|
||||
9700
|
||||
10e100
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// parentheses around numeric literal should be preserved
|
||||
function test5(): string {
|
||||
@@ -131,4 +155,28 @@ function test5(): string {
|
||||
0.5;
|
||||
0.5;
|
||||
|
||||
1;
|
||||
1.005;
|
||||
1.0;
|
||||
1.5;
|
||||
1.5;
|
||||
0;
|
||||
0.005;
|
||||
0.0;
|
||||
0.0;
|
||||
0.0;
|
||||
500600.001230045;
|
||||
1.005e60;
|
||||
1.0e60;
|
||||
0.005e60;
|
||||
0.0e60;
|
||||
0.0e60;
|
||||
0.0e60;
|
||||
0e60;
|
||||
0e60;
|
||||
500600.001230045e60;
|
||||
10;
|
||||
9700;
|
||||
10e100;
|
||||
|
||||
`;
|
||||
@@ -62,3 +62,27 @@ function test5(): string {
|
||||
0.5e+00
|
||||
0.5e-0
|
||||
0.5e-00
|
||||
|
||||
1
|
||||
1.00500
|
||||
1.0
|
||||
1.5
|
||||
1.50
|
||||
0
|
||||
0.00500
|
||||
0.0
|
||||
0.0000
|
||||
.0
|
||||
500600.001230045000
|
||||
1.00500e60
|
||||
1.0e60
|
||||
0.00500e60
|
||||
0.0e60
|
||||
0.0000e60
|
||||
.0e60
|
||||
0.e60
|
||||
0e60
|
||||
500600.001230045000e60
|
||||
10
|
||||
9700
|
||||
10e100
|
||||
Reference in new issue
Block a user