← Back to challenges

How Many Decimal Places?

JavaScriptHardnumbersstringsregex

Instructions

Create a function that returns the number of decimal places a number (given as a string) has. Any zeros after the decimal point count towards the number of decimal places.

Examples

getDecimalPlaces("43.20") ➞ 2

getDecimalPlaces("400") ➞ 0

getDecimalPlaces("3.1") ➞ 1

Notes

Return 0 if the number doesn't have any decimal places (see example #2).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Index Shuffle