Setting decimal places

1. Member
Join Date
Dec 1969
Posts
56

## Setting decimal places

How can i set the number of decimal places a number has. I have been using the round function but when a number returns as a whole number I need to place 3 0&#039;s behind the number. For example:<BR><BR>1 would become 1.000<BR>any idea&#039;s?

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## isn't there an FAQ on this yet???

convert to a string. find the decimal point. count it out from there.<BR><BR>basically<BR><BR>j

3. Senior Member
Join Date
Dec 1969
Posts
231

## RE: Setting decimal places

Use the formatnumber function, i.e. :<BR><BR>dim myNum<BR><BR>myNum = 1<BR>formatnumber(myNum,3) would give 1.000<BR><BR><BR>MikeD

4. Senior Member
Join Date
Dec 1969
Posts
614

## Using JavaScript

Math.Round() will round to the nearest integer. <BR>So, to round to a number of decimal places, multiply by 10,100 1000 etc, then Round, and then divide by the same number that you multiplied by <BR>Like this.. <BR><BR>var myNumber= "1.2345"; <BR>alert (Math.round(myNumber)); ==1 <BR>alert (Math.round(myNumber*10)/10); ==1.2 <BR>alert (Math.round(myNumber*100)/100); ==1.23 <BR>etc.. <BR>

5. Senior Member
Join Date
Dec 1969
Posts
19,082

## oops

I don&#039;t think in VBScript. good solution.<BR><BR>j

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•