Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2004, 11:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default Format Number

How do I format a number such as 43.46 to display as .4346?

Chris
 
Old October 26th, 2004, 09:08 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

  This is funny.


dim num,intdigits,divdigits,divisor,result,totchar
num=window.prompt("Enter number")
totchar=len(num)
intdigits=instr(num,".")
if intdigits>0 then
    divdigits=intdigits-1
    totchar=totchar-1
elseif intdigits=0 then
    divdigits=totchar
end if

for j=1 to divdigits
    divisor=divisor & "0"
next
divisor="1" & divisor

num=csng(num)
divisor=clng(divisor)
result=formatnumber((num/divisor),totchar)
alert num & " = " & result



ha ha ha

---------
Rajani

 
Old October 26th, 2004, 11:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

hahah, That was also an example of how to do things round about.

This is how easily you can do that in one line code.
Code:
<% Response.write FormatNumber(43.46/100,4,0) %>
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 27th, 2004, 11:11 AM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

Thanks Vijay!

How can that be used with an unknown string? The selection from a form will determine what the number that appears in the formatnumber function will be.

When getting info from a database, would the function work something like so:

Dim strNbr
strNbr = FormatNumber(objRS("number")/100,4,0)
 
Old October 27th, 2004, 11:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

I see what's happening now. Didn't quite understand at first, but after looking at it a little longer, I see it now. Works like a charm! Thanks again!

Chris





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number format in the table zrtv SQL Server 2005 6 March 7th, 2008 03:18 AM
format-number dropping 0 stolte XSLT 1 January 18th, 2008 04:46 PM
Format Number Dink Classic ASP Databases 2 January 23rd, 2007 01:40 AM
Number Format - Need Help! bridog39 Access 7 November 14th, 2005 02:50 PM
format number tgopal Javascript 2 April 30th, 2004 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.