Lesson #1 - Round to a number at any given place
[1/1] from: gmassar::dreamsoft::com at: 17-Oct-2000 11:36
REBOL fella:
Here is my first lesson for those who wish to do an exercise in order to
better understand REBOL. Old saying: the more practice, the better
programmer.
Write a function that performs rounding to a number at any given place.
Here are examples.
>> to-round 123.45
== 123
>> to-round 123.55
== 124
>> to-round -123.45
== -123
>> to-round/at 123.344 2
== 123.34
>> to-round 123.345 2
== 123.35
>> to-round/at 12345 -2
== 12300
>> to-round/at (1.22 // .01) 2
== 1E-2
NOTE: the last one is to answer the earlier message on this list.
Send your answer to my email at [gmassar--dreamsoft--com], not to this list.
I'll reply with my solution. In a couple of days or so, I'll post the
best solution with its author.
Have fun!
Geo (old professor)
Librarian comment
Later versions of REBOL have a round function as standard.