How to round up a number using VBScript?

# Thread: How to round up a number using VBScript?

1. dw
Junior Member
Join Date
Dec 1969
Posts
19

## How to round up a number using VBScript?

Hi,<BR><BR>This is what I want to do. If the number after the decimal point is greater than 0, then round up to the next highest integer.<BR><BR>Example:<BR><BR>1.2 will become 2<BR>3.8 will become 4<BR><BR>Thanks!!

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

## Try this...

Dim iValue<BR>iValue = Int(YourNumber + 1)<BR><BR>You can see the technical docs for the Int function at:<BR>http://help.activeserverpages.com/iishelp/VBScript/htm/vbs127.htm<BR><BR>HTH

3. J. Paul Schmidt Guest

## RE: How to round up a number using VBScript?

Perhaps use Int() or Fix() depending on how you want negative numbers to be rounded.<BR><BR>Best regards,<BR>-Paul<BR><BR>J. Paul Schmidt, MBA<BR>Databases on the Web<BR>http://www.Bullschmidt.com<BR><BR>

4. Member
Join Date
Dec 1969
Posts
40

## RE: How to round up a number using VBScript?

hi,<BR>U can round up a value using cint function.<BR><BR>example<BR>Dim MyDouble, MyInt<BR>MyDouble = 23.5678 &#039; MyDouble is a Double.<BR>MyInt = CInt(MyDouble) &#039; MyInt contains 24.<BR><BR> CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.<BR><BR>regards<BR>kk

5. Mike Shaffer Guest

## none of these were correct?? ;-)

However, this will accomplish what you asked for (assuming your value is in &#039;a&#039;:<BR><BR> response.write int(a+(abs(fix(a)&#060;&#062;a)))<BR><BR>You could build this into a function:<BR><BR>function RoundUp(a)<BR> RoundUp = int(a+(abs(fix(a)&#060;&#062;a)))<BR>end Function<BR><BR>and then use:<BR><BR> response.write RoundUp(a)<BR><BR>

6. dw
Junior Member
Join Date
Dec 1969
Posts
19

## RE: none of these were correct?? ;-)

Thanks, Mike, works like a charm. And thanks to the others who replied and made me aware of some other built-in functions i.e. int and fix!

7. Mike Shaffer Guest

## cool

You&#039;re welcome, and to be fair, I think that Scott&#039;s would have worked fine, but I think he meant to add .5 instead of 1... e.g.<BR><BR>iValue = Int(YourNumber + .5) <BR><BR>Anyway, glad it worked out!

#### Posting Permissions

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