$roundint(N).P <-- N rounded to nearest P

By vaseline28 on Jun 13, 2008

The following is a rounding function for whole numbers, not decimals as $round() does.

; Usage: $roundint(Number).P <---- Returns Number rounded to the nearest prop
; 'P' above must be a multiple of 10 and positive
; Example: $roundint(77).100 <--- returns 100
; Example II: $roundint(23).100 <--- returns 0

; Usage: $roundint(Number).P  <---- Returns Number rounded to the nearest prop
; 'P' above must be a multiple of 10 and positive
; Example: $roundint(77).100 <--- returns 100
; Example II: $roundint(23).100 <--- returns 0

alias roundint {
  if ($isid) {
    if ((!$1) || (!$prop) || ($prop !isnum)) { return Invalid Parameter }
    else {
      if ($1 !>= $prop) {
        return $iif($1 >= $calc($prop / 2),$prop,$calc($1 - $right($1,$count($prop,0))))
      }
      else {
        return $iif($right($1,$count($prop,0)) >= $calc($prop / 2),$calc($1 + ($prop - $right($1,$count($prop,0)))),$calc($1 - $right($1,$count($prop,0))))
      }
    }
  }
}

Comments

Sign in to comment.
vaseline28   -  Jun 14, 2008

Yep BlueThen, I considered that, but figured this was more useful! Thanks both.
Maths is not my favorite either, but I try!

 Respond  
EL   -  Jun 13, 2008

eeek math i ll pass =\ looks good tho.`-.-´

 Respond  
BlueThen   -  Jun 13, 2008

Pretty useful, seeing as how $round can only round to ones. (although you could just take your number, multiply it by 0.1, then use $round on it, then multiply it by 10).

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.