Rounding problem

1. ncw
Senior Member
Join Date
Dec 1969
Posts
614

## Rounding problem

I have this problem with rounding. I know that in VBScript, there is one function called round but my case can&#039;t use round function. Eg<BR><BR>1 / 8 = 0.125<BR>The value I want is = 1<BR><BR>The point is regardless of what I divide with, when it is more than 0, it will be rounded to be the larger integer.<BR><BR>If I put like that<BR><BR>(n / 8 ) + 1<BR><BR>I can but what if the n is 8. If n is 8, then my result is 2 instead of 1.

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Rounding problem

Let me get exactly straight what you&#039;re doing.<BR>1/8 = 0.125<BR>Which is over 0, so you want 1.<BR><BR>Can&#039;t the "Int()" function help? To take the integer portion of the value passed. Plus one, in your case.<BR><BR>?<BR><BR>Craig.

3. ncw
Senior Member
Join Date
Dec 1969
Posts
614

## RE: Rounding problem

Ok, more examples here.<BR><BR>0 - 0<BR>0.1875 - 1<BR>0.25 - 1<BR>0.4375 - 1<BR>0.5 - 1<BR>0.5625 - 1<BR>0.875 - 1 <BR>1 - 1<BR><BR>The left value is before round and the right value is after round.<BR><BR>Is the possible?

4. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Rounding problem

By sounds of it, you want something like this.<BR>[code language="VBScript"]<BR>Function MakeIntegerNumber(dNumber)<BR> MakeIntegerNumber = 0<BR> If IsNumeric(dNumber) = False Then Exit Function<BR> Dim dblNum: dblNum = CDbl(dNumber)<BR> Dim intNum: intNum = Int(dNumber)<BR> If intNum = dblNum Then<BR> &#039; It was an integer already<BR> MakeIntegerNumber = intNum<BR> Exit Function<BR> End If<BR> MakeIntegerNumber = (intNum + 1)<BR>End Function<BR>[/code]<BR><BR>Craig.

5. Junior Member
Join Date
Dec 1969
Posts
28

## RE: Rounding problem

How about..if x is the number -<BR><BR>if x&#062;int(x) then<BR> x=int(x+1)<BR>else<BR> x=int(x)<BR>end if<BR><BR>response.write (x)<BR>

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## LOL

Bit slow - that&#039;s exactly what my function does.<BR><BR>:-)<BR><BR>Craig.

7. Junior Member
Join Date
Dec 1969
Posts
28

## RE: LOL

Oops..just saw your reply...<BR><BR>Yeah..you got the elegant way to do it ;)

8. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: LOL

Of course, nsw, the solution(s) that were provided may not work correctly with negative numbers.<BR><BR>Depends on what output you want for them.<BR><BR>Craig.

9. ncw
Senior Member
Join Date
Dec 1969
Posts
614

## RE: Rounding problem

That&#039;s exactly what I need. I will just pick this simple one. Thanks to Reaper anyway.

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