Re: check decimal and if numeric



Okay, you have it solved.

Int() rounds down, so effectively truncates an subsequent digits for positive numbers. It's different when you round negative numbers down, e.g.:
- $2.281
would round down to:
- $2.29

If you don't want that behavior, use Fix() instead of Int().

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John" <johnboy7676@xxxxxxxxx> wrote in message
news:m9dgo358innuf6rq343i3ron25bpf08kbl@xxxxxxxxxx
I set the Format property as you suggested. That did prevent text from being
entered. And yes, that makes "cents"..-)

As for second suggestion, if for example, they input 25.228 instead of 25.22
then it would round to 25.23 when should be 25.22. And, if truncate at two
decimals, who's to say the third or fourth digit was the one that was in error?
Maybe the first digit after the decimal was the mistake.

I found something while searching google, it was suggested to use a Validation
Rule of :
=int(myfield*100)/100
which seems to work. I'm not sure why, but it does seem to work. (originally
posted by "Turtle")

Thanks, lots of good info on your web site, btw.


Personally, I hate input masks. There's probably a better way.

From your description, it seems that you want to make sure that:
a) the value is a valid number, and
b) the value has no more than 2 significant digits after the decimal.

For (a), set the text box's Format property to a numeric value, such as
Fixed. Set Decimal Places to 2 if you want to always show the 2 places.
Alternatives might be to use General Number (if the 2 places are really
optional) or Currency (if that makes cents.)

For (b), use the AfterUpdate event procedure of the text box to round the
value. This kind of thing:
Private Sub Text0_AfterUpdate()
Me.Text0 = Round(Me.Text0, 2)
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<johnboy7676@xxxxxxxxx> wrote in message
news:nvsfo39ds1bt11153jh1iqc8gduoo2vshs@xxxxxxxxxx
I have an unbound textbox, txtAmount. I want to make sure that user
enters only two decimal places, and that the input is numeric.

I tried using InputMask 99999999.99 which works for positive numbers,
but that mask won't allow the minus sign (or plus sign) to be used.
So, how can I allow input of a negative number? Currently, if
TransactType is "Payment", it takes the value in Amount * -1 (if
existing Amount > 0), so that effectively makes it a negative. But, a
TransactType of "Adjustment" could be either negative or positive. I
could make a TransactType of "Adjustment-negative" and
"Adjustment-positive", but there will probably be additional
TransactTypes added later, so think that might get me into trouble.

I can use If Not IsNumeric to check for numeric, but then I can't
check (or just don't know how) for number of decimal places.

Any suggestions? Thanks
John



.



Relevant Pages

  • Re: Truncating Numbers
    ... digits to the right of the decimal. ... decimals), but the number is still 12.3546. ... extra 2 digits at the end can cause the "across" sums ... There are 2 methods to round the computation. ...
    (microsoft.public.access.queries)
  • RE: prePEP: Decimal data type
    ... you may want to get rounded to two decimals: ... If you don't want 40 digits after the ... You do need to explicitly round after * and /. ... and each meaning has its own gang of frightened defenders ...
    (comp.lang.python)
  • Re: System.Math.Round bug (repost)
    ... Round(double value, int digits) ... It always seems to use the Round(decimal value, int decimals) version, no ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problems with Math.Round
    ... you need to role your own Round method like in this class: ... /// Rounds the double value to round to a specified number of decimals. ... Does not use Bankers Rounding. ... int digits) { ...
    (microsoft.public.dotnet.general)
  • Re: XQ and ->Qpi bug on large X
    ... you shouldn't be rounding to only two digits ... I am trying to make a similar point here about rounding; ... and round it, ... prior to using the input values in calculations. ...
    (comp.sys.hp48)

Loading