INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

FormatNumber

FormatNumber

(OP)
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

RE: FormatNumber

(OP)

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>")

RE: FormatNumber

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.

RE: FormatNumber

(OP)
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'

RE: 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>") 

RE: FormatNumber

(OP)
New error

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'cdbl'

RE: FormatNumber

(OP)
New error

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'cdbl'

RE: FormatNumber

Looks like RS(...) is NULL. Check that RS("TRANSPORTPRIS") is not null before writing it.

RE: FormatNumber

it is simple

CODE --> vbscript

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 

RE: FormatNumber

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

RE: FormatNumber

(OP)
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.

RE: FormatNumber

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close