Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormatNumber

Status
Not open for further replies.

hubit

Technical User
Jan 13, 2014
6
DK
HI

I am having troubles finding the right syntax
i have this syntax an it works fine but too many decimal places

response.write("<td align='right'>" + cstr(RS("TRANSPORTPRIS")&"") + "</td>")

I'm tryig to use Formatnumber cant make it work.
Hope someone has a suggestion

Thanks in advance

Jacob
 

I have tried a lot off kombinations
This
response.write("<td align='right'>" + cstr(RS("TRANSPORTPRIS")&"") + "</td>")
Works fine

Then i tried to kombine it with the FormatNumber

response.write("<td align='right'>" + FormatNumber(cstr(RS("TRANSPORTPRIS"))&""),2 + "</td>")
response.write("<td align='right'>" + Formatnumber(rs("TRANSPORTPRIS"),2) + "</td>")

 
FormatNumber requires a number: not a string. So if you want two decimal places, it would be
Code:
response.write("<td align='right'>" & FormatNumber(RS("TRANSPORTPRIS"),2) & "</td>")
The second one should have worked except possibly you used + instead of & for string concatenation. Use + for javascript, & for vbscript.
 
Ok there have been used + ind all the other lines
So when I use the (have tried the & as well
response.write("<td align='right'>" + FormatNumber(RS("TRANSPORTPRIS"),2) + "</td>")

I keep getting the error


Microsoft VBScript runtime error '800a000d'

Type mismatch: 'FormatNumber'

 
I think RS("TRANSPORTPRIS") returns a string. Try converting it to a double before formatting
Code:
response.write("<td align='right'>" & FormatNumber(cdbl(RS("TRANSPORTPRIS")),2) & "</td>")
 
New error

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'cdbl'
 
New error

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'cdbl'
 
Looks like RS(...) is NULL. Check that RS("TRANSPORTPRIS") is not null before writing it.
 
it is simple
Code:
if cstr(RS("TRANSPORTPRIS")&"")<>"" then 
response.write("<td align='right'>" &  FormatNumber(cdbl(RS("TRANSPORTPRIS")),2) & "</td>") 
else
response.write("<td align='right'></td>") 
end if
 
What's wrong with the IsNull() function?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi

When I use the code from gk53 everything is workngust fine.

I haven't used th idNumeric() ane IsNull() funktion. I'l try them another day.

Thank you for all the help.
 
I use cstr(RS("TRANSPORTPRIS")&"")<>"" becouse isNull check for null value, but will not catch "" value it is not null, so you should have to chack for isNull() and cstr(RS("TRANSPORTPRIS"))<>"" or isNumeric().
IsNumeric() check just for numeric value and if it is null not catching that...
I think
if cstr(RS("TRANSPORTPRIS")&"")<>"" then

simpler then
if ((not isNull(RS("TRANSPORTPRIS"))) and isNumeric(RS("TRANSPORTPRIS"))) then

(extra parenteces just for readability) [dazed]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top