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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying formatted decimal places

Status
Not open for further replies.

moltar

Programmer
Mar 8, 2002
26
US
I have an integer field that has a number * 1000, for example 4950. I am in need of having it display on a webpage as 4.950

Similarly, 5000 would need to display as 5.000 and 6251 would need to display as 6.251

How can I accomplish this?

Thanks much for any help that can be offered!
 
You would need to divide by 1000.0. By adding the ".0" to the end of 1000 you are telling SQL that you want to include decimal places. If you just divide by 1000, SQL only returns the integer part, without rounding.

[expression] / 1000.0

Dan.
 
Thanks Dan1967 for trying to help me out. Unfortunately, I'm not getting any better results; maybe I'm doing something wrong?

I tried:
rsCurrentList("an_average")/1000.0

and nothing changed in my display. I tried "rsCurrentList("an_average")/1000.000" as well, but nothing happened either.

How can I get rsCurrentList("an_average"), when it is equal to 5000, display as 5.000? And if it were equal to 4950, it would display as 4.950?

Thanks!
 
your problem here is with your ASP display rather than your SQL Server logic - (and there's an ASP forum for that) - but here's something to help you out anyway:

ADO recordsets (commonly used in ASP to hold results of SQL queries) are entirely text based (to my knowledge) so rsRecordset("fieldName") gives you a 'string' representing what was in fieldName.

In your example rsCurrentList("an_average") gives you "5000" and not the integer 5000 (which is what you want to divide by 1000.00)

so, by referring to the MS VBscript reference ( I can find a CDbl function to convert to a double (number with approximate decimal places)

So.. try this:
Code:
CDbl(rsCurrentList("an_average"))/1000.0
I'm sure you can work out how to get it to display the amount of decimal places you want :)

good luck


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top