Created
December 29, 2022 13:45
-
-
Save DevGW/be7b22227e4f2b94b0b35abf1da95faa to your computer and use it in GitHub Desktop.
Javascript :: toString and parseFloat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zeroDarkThirty = (aNum) => { | |
const stringNum = aNum.toString(); | |
let zerolessString = ''; | |
for (let i = 0; i < stringNum.length; ++i) { | |
const currentDigit = stringNum[i]; | |
if (currentDigit !== '0') zerolessString += currentDigit; | |
} return parseFloat(zerolessString); | |
} | |
// this takes a number and gets rid of the zeroes, and returns the zeroless number. | |
// parseFloat returns number with decimal places | |
// parseInt would return integer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment