"zxcv" wrote:
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.
Try:
If Round(inval,2) = inval Then
Normally, I would opt for WorksheetFunction.Round or even
Evaluate("round(...)") instead of the
VB Round function. There are
functional differences. In this case, I do not think it makes a difference.
Nevertheless, you might want to use one of those alternatives instead, just
to be sure.
----- original message -----
"zxcv" wrote in message
...
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?