Z
zxcv
I need to do some input validation so to check if a value has no more
than 2 decimal digits. So 14.12 is valid but 14.123 is not.
I have tried doing a check like this:
If Int(inval * 100) <> inval * 100 Then
but this gets a rounding error with certain values like 2.22. If I
subtract one side above from the other I get a difference on the order
of 10^-21.
So I tried rounding the numbers to do a test like this:
If Round(Int(inval * 100), 10) <> Round(inval * 100, 10) Then
and this does something weird like rounding Round(Int(0.29 * 100), 10)
to 28.
Is there some simpler way to check that a number does not have too
many decimal digits?
than 2 decimal digits. So 14.12 is valid but 14.123 is not.
I have tried doing a check like this:
If Int(inval * 100) <> inval * 100 Then
but this gets a rounding error with certain values like 2.22. If I
subtract one side above from the other I get a difference on the order
of 10^-21.
So I tried rounding the numbers to do a test like this:
If Round(Int(inval * 100), 10) <> Round(inval * 100, 10) Then
and this does something weird like rounding Round(Int(0.29 * 100), 10)
to 28.
Is there some simpler way to check that a number does not have too
many decimal digits?