I needed a simple two decimal place round off function for a script this
evening.

This is what I came up with:

roundoff: func ["Rounds off to 2 decimal places" a][
        a: a * 100
        b: a - to-integer a
        a: to-integer a
        if b > .5 [a: a + 1]
        a: divide a 100
        ]

Here's how it works:

>> roundoff 10.567890
== 10.57
>> roundoff 10.563333
== 10.56

Can anyone improve on this, or is there a function already in REBOL I
overlooked?

Okay, yes, to-money does it:

>> to-money 10.567
== $10.57
>> to-money 10.563
== $10.56

but I want the decimal! type.

--Ralph Roberts


Reply via email to