[REBOL] Re: Rounding
From: rpgwriter:yah:oo at: 30-May-2002 18:50
--- Mat Bettinson <[mat--0wnerage--com]> wrote:
> Folks,
>
> >> print to-integer 1.6
> 1
>
> I can't for the life of me find a word which does
> the same as this but
> which actually rounds (so you'd get 2) rather than
> just chopping off
> the remainder.
>
> Is there such a beast or must one write a function
> to do it?
I don't think there is one, but it shouldn't be too
ugly. Rounding fractions >=0.5 away from 0, do this:
round-off: func [ x [number!] ] [
return either greater? x 0 [
to-integer x + 0.5
] [
to-integer x - 0.5
]
]