andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 306 forks source link

Feature request: Number#fround(precision) #560

Closed Slayer95 closed 7 years ago

Slayer95 commented 7 years ago

In analogy to Number#round().

andrewplummer commented 7 years ago

While Number#round allows you to control the precision, this doesn't seem to require that, so it could just be mapped as an alias similar to pow, abs, etc. Would this satisfy your needs?

Slayer95 commented 7 years ago

The idea is for Number#fround to do allow to control precision, in the same way as Number#round does.

Note that neither Math.round nor Math.fround themselves have a precision parameter built-in.

I'm currently shimming it like so, btw: Number#fround

andrewplummer commented 7 years ago

So, after playing around with your example a bit, I'm still having trouble understanding the meaning (or at least the utility) of having a "places" argument. round is clear as this is natural language. Although according to the spec it rounds to the nearest integer, it is not a stretch for a parameter to allow rounding to a specific place. fround, however is not natural language, the method specifically rounds to single-precision, and the places argument isn't immediately clear what it's indicating.

Anyway, let's set all this feedback aside. In either case, this idea is a perfect candidate for using the new plugin system of v2.0. I just recently created a boilerplate repo here. There are a lot of notes and it should be easy to follow along.

andrewplummer commented 7 years ago

Going to close this for now. Let me know if there are issues with the plugin mechanism, etc.