How do I round up?

Results 1 to 4 of 4

Thread: How do I round up?

  1. #1
    I have question Guest

    Default How do I round up?

    I know there is a Round function which goes like this:<BR>Round(expression[, numDecimalPlaces])<BR>But this function returns rounded number, not rounded up or rounded down... I thought about this script:<BR>if round(x/y,0) not x/y then<BR>a = round(x/y)+1<BR>else<BR>a = x/y<BR>end if<BR><BR>Does anyone here know any shorter way?

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default RE: How do I round up?

    See if this helps<BR><BR>

  3. #3
    I have question Guest

    Default Actualy... No...

    But I got a better script now...:<BR>a = Round(x/y+0.49,0)<BR>If x/y has no digits after the decimal point, it would be rouned down, and won&#039;t change the expression x/y, and if it is bigger, it would return the x/y+1.

  4. #4
    Join Date
    Dec 1969

    Default You *almost* have it right...

    It should be<BR><BR>If X &#060;&#062; Int(X) Then X = Int(X)+1<BR><BR>To see why, consider rounding 3.00001<BR><BR>With your version, 3.00001+0.49 --&#062;&#062; 3.49001 which *still* rounds to 3.0<BR><BR>Incidentally, if you think that you won&#039;t have any values such as 3.00001, then you may need to look at how floating point numbers actually work. You can *easily* get 3.00001 (well, more likely 3.0000000000001) when you do floating point arithmetic that you *think* is giving you just 3.0 as the result. It&#039;s just the nature of the beast.<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