Round Off

1. Unni Krishnan Guest

## Round Off

What function does one use for rounding off in ASP.

2. Rob Guest

## RE: Round Off

You can just use CINT<BR><BR>This will round off for you

3. Senior Member
Join Date
Dec 1969
Posts
2,849

## RE: Round Off

You can also use these functions:<BR><BR>Round (http://help.activeserverpages.com/iishelp/VBScript/htm/vbs177.htm)<BR><BR>Int (http://help.activeserverpages.com/iishelp/VBScript/htm/vbs127.htm)<BR><BR>Fix (http://help.activeserverpages.com/iishelp/VBScript/htm/vbs127.htm)<BR><BR>Happy Programming!

4. Brian Bell Guest

## RE: Round Off

IMPORTANT!<BR>VB uses non-standard rounding! If a value is &#062; x.5 it rounds up. If it is &#060; x.5 it rounds down. If it is exactly x.5 it rounds to the nearest EVEN number!<BR><BR>To correct this you can use the following function (trueRound) instead of round: <BR>&#039***************************************** *********<BR>&#039*<BR>&#039* VBScript rounds x.5 to the nearest EVEN number.<BR>&#039* This function is to correct to numeric rounding<BR>&#039*<BR>&#039*********************** ***************************<BR>function trueRound(myVar)<BR> dim intTemp<BR> intTemp = round(myVar)<BR> if ((myVar - intTemp) = 0.5) then <BR> intTemp = intTemp + 1<BR> end if<BR> trueRound = intTemp<BR>end function<BR><BR>Have Fun!

5. Senior Member
Join Date
Dec 1969
Posts
487

## Shootin' my mouth off?

I&#039m no VB Script functions &#039Master&#039 so I won&#039t go shootin&#039 my mouth off here ...... BUT -<BR><BR>Try running this script in your browser and see the results for yourself. It seems to me that the good old TrueRound() function (god bless it&#039s soul) returns the same as the Round function at every turn.<BR><BR>&#060;%@ language="VBScript" %&gt;<BR>&lt;%<BR>Option Explicit<BR><BR>Dim i<BR><BR>function trueRound(myVar) <BR>&nbsp;&nbsp;&nbsp;dim intTemp <BR>&nbsp;&nbsp;&nbsp;intTemp = round(myVar) <BR>&nbsp;&nbsp;&nbsp;if ((myVar - intTemp) = 0.5) then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intTemp = intTemp + 1 <BR>&nbsp;&nbsp;&nbsp;end if <BR>&nbsp;&nbsp;&nbsp;trueRound = intTemp <BR>end function <BR><BR>For i = 1 to 10 Step .1<BR><BR>Response.Write "&lt;p&gt;"<BR>Response.Write "The number is: " & i & "&lt;BR&gt;"<BR>Response.Write "The Round function returns: " & Round(i,0) & "&lt;BR&gt;"<BR>Response.Write "The True Round function returns: " & TrueRound (i) & "&lt;BR&gt;"<BR><BR>Next<BR>%&gt;<BR><BR>Enjoy?<BR ><BR>Darren<BR>darren@showusyourcode.com

6. Brian Bell Guest

## RE: Shootin' my mouth off?

Hmmm?<BR>OK. Try rounding 1.5, 2.4, 2.5, 2.6, and 3.5<BR>VB and VBScript round and Int functions produces the following:<BR>1.5 &#062; 2 *Correct*<BR>2.4 &#062; 2 *Correct*<BR>2.5 &#062; 2 **Incorrect**<BR>2.6 &#062; 3 *Correct*<BR>3.5 &#062; 4 *Correct*

7. Senior Member
Join Date
Dec 1969
Posts
487

## OOoooops!

Sorry Brian,<BR><BR>I don&#039t think that I was looking hard enough the first time.<BR><BR>Your function *does* work a treat and now it&#039s in my Utilities.inc file.<BR><BR>THANKYOU :))<BR>Darren

8. Filip Honzarek Guest

## RE: Round Function

Hi, short function...<BR><BR>Function trueRound(Num)<BR> trueRound = Int(Num + 0.5)<BR>end function<BR><BR><BR>

9. Junior Member
Join Date
Dec 1969
Posts
10