Joe User
3/24/2010 5:36:00 PM
"zxcv" <zxcvnosend@yahoo.com> wrote:
On Mar 24, 12:31 pm, "Joe User" <joeu2004> wrote:
> > Try:
> > If Round(inval,2) = inval Then
[....]
> Thanks for the input but I need to do this in VBA
> as I have no control over the input and cannot put
> any formulas in the sheet. Someone else enters the
> data and then another person hits a button that I
> created.
I don't understand your comment. What I wrote is for VBA, and it is
intended to deal with exactly the situation that you describe. I think you
misunderstand my comments. Perhaps you should just give it a try.
PS: Sorry, I wrote "=" where you wanted "<>". That's a simple change, heh?
----- original message -----
"zxcv" <zxcvnosend@yahoo.com> wrote in message
news:6d74dc36-1fae-4269-8bba-dd366ae0b776@g28g2000yqh.googlegroups.com...
On Mar 24, 12:31 pm, "Joe User" <joeu2004> wrote:
> "zxcv" <zxcvnos...@yahoo.com> 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" <zxcvnos...@yahoo.com> wrote in message
>
> news:3466ddcc-9050-4873-9377-bcaee5b6517e@z3g2000yqz.googlegroups.com...
>
> >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?
Thanks for the input but I need to do this in VBA as I have no control
over the input and cannot put any formulas in the sheet. Someone else
enters the data and then another person hits a button that I created.