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

Displaying A Number With 2 Places Beyong the Decimal Point 1

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
I have a script which reads through a set of numbers
that can have a value up to two place beyond the decimal point ( eg. 1.99, 1.9, 1 etc. ). When I display these numbers as a list on my html page generated by my asp script, they do not line up on the decimal point. Example:-

10.9
1.7
250.89
20.71
78.1
11

Is there a clever way of forcing a number to be written to Response.Write a number with padded two decimal places ( so that 1.7 become 1.70, 11 become 11.00 etc ). the only alternative I can think of is to concatonate a string verion of the number with '0' or '.00' and reposnse.write the string instead of the number which seems a bit poor.

Many thanks
 
hi,
do this:
number=10.9
strn=split(cstr(number),".")
newstr=strn(0)
if len(strn(1))=1 then
newstr=newstr+"."+strn(1)+"."+"0"
else
newstr=newstr+"."+strn(1)
end if
response.write newstr




Known is handfull, Unknown is worldfull
 
Or try this ...
Code:
Dim Number

Number = 10.9
Response.Write FormatNumber(Number, 2)
The second parameter to FormatNumber is the number of decimal places that should be shown.

This will work as VBScript within ASP executing on the server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top