ramda-adjunct icon indicating copy to clipboard operation
ramda-adjunct copied to clipboard

roundTo

Open char0n opened this issue 7 years ago • 1 comments

Is your feature request related to a problem? Please describe. Round to a certain precision on a number

Describe the solution you'd like

roundTo(2, 11); // outputs 12
roundTo(3, 11); // outputs 12
roundTo(4, 11); // outputs 12
roundTo(5, 11); // outputs 10
roundTo(6, 11); // outputs 12
roundTo(7, 11); // outputs 14
roundTo(8, 11); // outputs 8
roundTo(0.5, 3.7); // outputs 3.5
roundTo(0.5, 3.75); // outputs 4
roundTo(0.5, 3.8); // outputs 4

Describe alternatives you've considered

Additional context

function round_to_precision(x, precision) {
    var y = +x + (precision === undefined ? 0.5 : precision/2);
    return y - (y % (precision === undefined ? 1 : +precision));
}

https://github.com/lodash/lodash/issues/2310 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round

char0n avatar Jul 28 '17 13:07 char0n

RA.round is already implemented. Transforming this issue into R.roundTo.

char0n avatar Dec 24 '19 14:12 char0n