Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel formula for count numbers of decimals

Tags:

excel

I need to count the numbers of decimals places of a number.

The A1 cell value is:

    123456.78.

The formula in B1 is:

    =LEN(MOD(A1,1))

The results of MOD(A1,1) is:

 0.78

I expected the LEN to be 4 (LEN(0.78)=4). The Excel formula calculates 17 because the forumula returns:

0.779999999998836

Should I try a different approach? For example looking for the separator char?

=LEN(A1)-FIND(".",A1)
like image 316
daniele Avatar asked Oct 16 '25 17:10

daniele


1 Answers

I see that the Len function is causing the math function to return the incorrect value for some reason (Len(Mod(123456.78, 1)) is returning 17 not 4, whereas Len(Mod(6.78,1) correctly returns 4).

You can add the TEXT function to your formula to change it to text, with a format of "General" to preserve the decimal precision, before calculating the length: LEN(TEXT(MOD(A1,1), "General")).

For those wanting to use this to calculate the number of decimal places without the leading "0.", simply subtract 2 from the result.

like image 125
David Avatar answered Oct 18 '25 06:10

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!