mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Enhance createRound by using toNumber to allow binary and octal strings.
This commit is contained in:
committed by
John-David Dalton
parent
ec8ccbcc55
commit
3eda8e64f3
@@ -4148,15 +4148,15 @@
|
||||
function createRound(methodName) {
|
||||
var func = Math[methodName];
|
||||
return function(number, precision) {
|
||||
number = toNumber(number);
|
||||
precision = precision ? toInteger(precision) : 0;
|
||||
if (precision) {
|
||||
// Shift with exponential notation to avoid floating-point issues.
|
||||
// See [MDN](https://mdn.io/round#Examples) for more details.
|
||||
var pair = (+number + 'e').split('e'),
|
||||
value = func(pair[0] + 'e' + (+pair[1] + precision));
|
||||
|
||||
var pair = (toString(number) + 'e').split('e'),
|
||||
value = toString(func(pair[0] + 'e' + (+pair[1] + precision)));
|
||||
pair = (value + 'e').split('e');
|
||||
return +(pair[0] + 'e' + (pair[1] - precision));
|
||||
return +(pair[0] + 'e' + (+pair[1] - precision));
|
||||
}
|
||||
return func(number);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user