Skip to content

Commit be28606

Browse files
authored
Create toFixed.js
1 parent 708e2a2 commit be28606

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

BuildIn-Methods/toFixed.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fixNum = (num, n = 2) => Number.parseFloat(num).toFixed(n);
2+
3+
console.log(fixNum(123.456));
4+
// expected output: "123.46"
5+
6+
console.log(fixNum(0.004));
7+
// expected output: "0.00"
8+
9+
console.log(fixNum('1.23e+5', 4));
10+
// expected output: "123000.0000"

0 commit comments

Comments
 (0)