mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
Merge pull request #512 from JakeGerber/master
Added decimalIsolate function.
This commit is contained in:
17
Maths/decimalIsolate.js
Normal file
17
Maths/decimalIsolate.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* function isolates the decimal part of a number.
|
||||
* Take the number and subtract it from the floored number.
|
||||
* Return the result.
|
||||
*/
|
||||
|
||||
const decimalIsolate = (number) => {
|
||||
const ans = parseFloat((number + '').replace(/^[-\d]+./, '.'))
|
||||
return isNaN(ans) === true ? 0 : ans
|
||||
}
|
||||
|
||||
// testing
|
||||
console.log(decimalIsolate(35.345))
|
||||
console.log(decimalIsolate(56.879))
|
||||
console.log(decimalIsolate(89.5643))
|
||||
console.log(decimalIsolate(38.00))
|
||||
console.log(decimalIsolate(33))
|
||||
Reference in New Issue
Block a user