FormatNumber Vs Round.....HELP...........

# Thread: FormatNumber Vs Round.....HELP...........

1. Junior Member
Join Date
Dec 1969
Posts
10

## FormatNumber Vs Round.....HELP...........

I am running into big problem really.<BR>In my orders page the Round and Format number are messing up everything.<BR>Please guys somebody help me out.<BR>suppose a variable <BR>a = 5.657<BR>what should be the actual value that I should use. I want 2 decimal places.<BR>I also found out that FormatNumber converts a number into string, how is that?<BR>Also if someone can tell me when to use Round and when to use FormatNumber<BR>Please help me out<BR><BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
5,955

## FormatNumber and Round have...

...two different purposes. FormatNumber is used to display numbers on screen, which is why it converts a number into a string. It&#039;s a very useful function if you need to display your number values in a standard way.<BR><BR>Round on the other hand is used to... well... round numbers for use in calculations. If, for example, you have a fraction, but you&#039;re not interested in all the decimal places, then use round. In particular, if you want to use the result in another calculation.<BR><BR>By the sounds of it, you want to use Round, because you&#039;re storing the numbers somewhere and then using them for other calculation.<BR><BR>If you check out the documentation for Round on the Microsoft website (http://msdn.microsoft.com/library/en-us/script56/html/vsfctRound.asp), you&#039;ll see how to use it.<BR><BR>For example:<BR><BR>a = 5.657<BR>aRoundedToTwoDecimals = Round(a, 2)<BR><BR>If a is an average price, then aRoundedToTwoDecimals would round this to pounds and pence, or dollars and cents, or whatever. Then you could use that to calculate tax, or other stuff.<BR><BR>Hope this makes sense.<BR><BR>Oliver.

3. Junior Member
Join Date
Dec 1969
Posts
10

## RE: FormatNumber and Round have...

But in a while loop<BR>I am displaying the value of "a" and also want to use teh value in formula<BR>so using formatnumber to display and using round in formula may give different results. Here what I found out<BR>c = 34.995<BR>a = FormatNumber(c, 2)<BR>b = Round(c, 2)<BR><BR>which returns <BR>a = 35<BR>b = 34.99<BR><BR>such values make lots of difference in Purchase orders<BR>which one is best suitable.<BR>I have decided that to use Formatnumber everywhere<BR>thanks

4. Senior Member
Join Date
Dec 1969
Posts
5,955

## That is strange, indeed. I don't...

...know why the results should be any different, but obviously the functions are rounding differently.<BR><BR>I suggest you only use Round, so you can still do your calculations, and when you Response.Write a number after you rounded it, it should display fine:<BR><BR>c = 34.995<BR>b = Round(c, 2)<BR><BR>Response.Write "c: " & c & " - b: " & b<BR><BR>Oliver.

5. Junior Member
Join Date
Dec 1969
Posts
10

## RE: That is strange, indeed. I don't...

one solution is in my mind is<BR>First use Round and then use formatnumber<BR>so the values will be consitent everywhere<BR> c = 34.995<BR> a = FormatNumber(Round(c, 2), 2)<BR> b = Round(c, 2)<BR><BR>this will return 34.99 for both a,b<BR>what do you say?<BR><BR><BR>regards,<BR>Mayur

6. Senior Member
Join Date
Dec 1969
Posts
5,955

## Why use FormatNumber() if you...

...already use Round()? Just Reponse.Write it or whatever.<BR><BR>Oliver.

7. Junior Member
Join Date
Dec 1969
Posts
10

## RE: Why use FormatNumber() if you...

the issue over here is,<BR>there are 10 different values<BR>I am displaying and also adding the values to calculate total<BR>The problem is I should use the same syntax in calculation that I am using for display purpose. In this scenario Round and formatNumber are giving problem<BR><BR>anyway thanks for your reply,<BR>if anything comes upto your mind then mail me to <BR>natumayur@rediffmail.com<BR><BR>

#### Posting Permissions

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