I have a field returned from a query. This field will either be a number or
a string, the string will be a code that explains why there is no number. I
use a function to sort that out (see bottom of this post)

Now I have a number 94.8892254 in str

If I run FormatNumberIfNumeric(str) I get "95" I should get "95.00". How
do I fix this?

Thanks
MIke

Function FormatNumberIfNumeric(str)
If Isnumeric(str) then
FormatNumberIfNumeric = FormatNumber(str, 2, -1, 0, 0)
Else
If str = "" or ISNull(str) then
FormatNumberIfNumeric = "<b>???</b> "
Else
FormatNumberIfNumeric = str & "boo"
End If
End If
End Function

Re: number formatting by Tim

Tim
Mon Oct 10 11:03:50 CDT 2005

Hi Mike,

That's very odd. I've tested your code and it works fine for me so
something else might be going on?

I expect that FormatNumber(str, 2, -1, 0, 0) will return the number in
str rounded to 2 decimal places, with a leading zero if the result is
less than 1, without brackets around negative numbers and without
breaking large numbers with a comma.

That's exactly what I'm getting with your function:

I pass in "94.8892254" and I get 94.89
I pass in "94.1" and I get 94.10
I pass in "0" and I get 0.00
I pass in "-1.234" and I get -1.23
I pass in "123,456.000" and I get 123456.00
I pass in "" and I get "<b????</b>"
I pass in "a" and I get "aboo"

I tried fiddling with my regional settings, but I still couldn't
reproduce the behaviour you are experiencing.
I am vexed!

I'm running winxp proffessional with service pack 2.

Tim