How Many Decimal Places?

Published by Joshua Señoron in

Create a function that returns the number of decimal places a number has. Any zeros after the decimal point count towards the number of decimal places.

Examples

get_decimal_places("43.20") ➞ 2

get_decimal_places("400") ➞ 0

get_decimal_places("3.1") ➞ 1

Notes

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

Watch a quick demo on how Edabit works.