Skip to content

Commit ef78fce

Browse files
authored
Update decimalIsolate.js
The previous code was not efficient enough to give the accurate output.
1 parent ac4bd9f commit ef78fce

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Maths/decimalIsolate.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66

77
const decimalIsolate = (number) => {
8-
return number - Math.floor(number)
8+
const ans = parseFloat((number + '').replace(/^[-\d]+./, '.'))
9+
return isNaN(ans) === true ? 0 : ans
910
}
1011

1112
// testing
1213
console.log(decimalIsolate(35.345))
1314
console.log(decimalIsolate(56.879))
1415
console.log(decimalIsolate(89.5643))
16+
console.log(decimalIsolate(38.00))
17+
console.log(decimalIsolate(33))

0 commit comments

Comments
 (0)