By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

formatnumber function returns error

P: n/a
The following code with formatnumber function returns me the following
code. Why? Thanks.
<td align="right"><Font
class=content4><%=formatNumber(ars.Fields("SOLD_AM OUNT"),2)%></td>

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'formatNumber'
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Are you sure SOLD_AMOUNT is a number and it not null?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"eddie wang" <ew***@kmg.com> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
The following code with formatnumber function returns me the following
code. Why? Thanks.
<td align="right"><Font
class=content4><%=formatNumber(ars.Fields("SOLD_AM OUNT"),2)%></td>

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'formatNumber'
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #2

P: n/a
eddie wang wrote on 11 feb 2004 in microsoft.public.inetserver.asp.general:
<%=formatNumber(ars.Fields("SOLD_AMOUNT"),2)%>

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'formatNumber'


Make sure ars.Fields("SOLD_AMOUNT") is always a number

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3

P: n/a
There is null value. IS there anyway to use formatnumber and other
functions to say if there is null then not to use formatnumber, else use
formatnumber??

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4

P: n/a
eddie wang wrote:
There is null value. IS there anyway to use formatnumber and other
functions to say if there is null then not to use formatnumber, else
use formatnumber??

Thanks.


Create a NullToZero function:

function NullToZero(pData)
if len(pData) = 0 then
NullToZero = cdbl(0)
else
on error resume next
pData = cdbl(pData)
if not IsNumeric(pData) then pData = 0
NullToZero = cdbl(pData)
end if
end function

Then use the function in your call to FormatNumber:
<%=formatNumber(NullToZero(ars.Fields("SOLD_AMOUNT ")),2)%>

HTH.
Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #5

P: n/a
Why is there a NULL value? Why are you displaying a NULL value? Why are
you pulling a NULL value from your database? Can you not make the query
return 0 if it's NULL, or does that have a different meaning?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"eddie wang" <ew***@kmg.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
There is null value. IS there anyway to use formatnumber and other
functions to say if there is null then not to use formatnumber, else use
formatnumber??

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #6

P: n/a
0 means there is a value of 0. Null means there is no value. There is
difference between 0 and null.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #7

P: n/a
eddie wang wrote:
0 means there is a value of 0. Null means there is no value. There
is difference between 0 and null.

You cannot use FormatNumber on an empty string or a Null value. If you do
not want to display anything when the field contains a Null, then you will
need to use some logic to determine whether the value is written to the
response or not:
<%=
if len(ars.Fields("SOLD_AMOUNT")) > 0 then
formatNumber(ars.Fields("SOLD_AMOUNT"),2)
end if
%>

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #8

P: n/a
> 0 means there is a value of 0. Null means there is no value. There is
difference between 0 and null.


Thanks, I understand the difference between 0 and NULL. I was asking if it
matters for YOUR scenario (often it doesn't, and NULLs weren't meant to be
allowed in the database).

If you need to differentiate between 0 and NULL, then you will need to check
somehow, either by including a flag in the query or checking the actual
value as Bob showed.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #9

P: n/a
This NullToZero function will replace all the null values to 0. Is
there a way to display all the null values as they are and to display
the rest with two decimals? Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #10

P: n/a
> This NullToZero function will replace all the null values to 0. Is
there a way to display all the null values as they are and to display
the rest with two decimals? Thanks.


What does "as they are" mean? Do you want the word NULL to be written to
the screen, or do you want an empty space, or do you want "n/a", or do you
want "I don't know why I have NULLs here", or do you want something else?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #11

P: n/a
eddie wang wrote:
This NullToZero function will replace all the null values to 0. Is
there a way to display all the null values as they are and to display
the rest with two decimals? Thanks.


I think I answered this in my other post.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.