Excel VBA account numbers before and after the decimal

advertisements

Im trying to count the numbers before and after a decimal place.

For example 1452.13 before would be 4 before and after would be 2.

The value is stored in a string i think i may need to use the len with find but cannot figure it out?

would appreciate any help.


Can I play too? :D

Num = 1452.13
Debug.Print Len(Split(Num, ".")(0)) '<~~ Length of number before decimal
Debug.Print Len(Split(Num, ".")(1)) '<~~ Length of number After decimal

EDIT:

I am assuming that you will pass only decimals. But to make it foolproof, you can use this

Num = 1452

Debug.Print Len(Split(Num, ".")(0)) '<~~ Length of number before decimal

If InStr(1, Num, ".") Then Debug.Print Len(Split(Num, ".")(1)) _
Else Debug.Print 0 '<~~ Length of number After decimal