Numeric#round_to

G

Gavin Kistner

I suspect someone (many people) have already done this, previously, but
I needed the practice.

I've ported the ECMAScript algorithm for Number.prototype.toFixed() to
Ruby, and it's now included in my generically-named 'basiclibrary.rb'
file as Numeric#round_to, available at
http://phrogz.net/RubyLibs/

(The full basiclibrary.rb file is available for download if you click
on 'basiclibrary.rb' in the Files column, and then click on the "Full
Code:" link near the top of that page.)

While this solution works, is this not the sort of thing that should be
part of the built-ins? Would there be any objections to an RCR for
including this functionality (not necessarily my
sloppy-and-likely-inefficient code) in the built-in Numeric class?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top