Skip to content

Commit 901432e

Browse files
authored
Merge pull request #512 from JakeGerber/master
Added decimalIsolate function.
2 parents efc427e + ef78fce commit 901432e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Maths/decimalIsolate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* function isolates the decimal part of a number.
3+
* Take the number and subtract it from the floored number.
4+
* Return the result.
5+
*/
6+
7+
const decimalIsolate = (number) => {
8+
const ans = parseFloat((number + '').replace(/^[-\d]+./, '.'))
9+
return isNaN(ans) === true ? 0 : ans
10+
}
11+
12+
// testing
13+
console.log(decimalIsolate(35.345))
14+
console.log(decimalIsolate(56.879))
15+
console.log(decimalIsolate(89.5643))
16+
console.log(decimalIsolate(38.00))
17+
console.log(decimalIsolate(33))

0 commit comments

Comments
 (0)