Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding issue #4529

Closed
L2jLiga opened this issue Oct 28, 2019 · 4 comments
Closed

Rounding issue #4529

L2jLiga opened this issue Oct 28, 2019 · 4 comments
Labels

Comments

@L2jLiga
Copy link

L2jLiga commented Oct 28, 2019

version: master

input: _.round(-1.4445, 3)

expected: -1.445
actual: -1.444

@jamesplease
Copy link

The behavior of Lodash here is consistent with Math.round, so I think it is expected. From MDN (it's long, sry 🤷‍♂emphasis mine ):

If the fractional portion of the argument is greater than 0.5, the argument is rounded to the integer with the next higher absolute value. If it is less than 0.5, the argument is rounded to the integer with the lower absolute value. If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +∞. Note that this differs from many languages' round() functions, which often round this case to the next integer away from zero, instead giving a different result in the case of negative numbers with a fractional part of exactly 0.5.

Test cases:

Math.round(1.5);
// => 2

Math.round(-1.5);
// => -1

@shauntck
Copy link

shauntck commented Nov 4, 2019

i just ran across an issue myself.
Using:
import { round } from 'lodash';
round(123.23233, 2) // 123.23

import { round } from 'lodash/fp';
round(123.2333, 2) // 123

@jamesplease
Copy link

@shauntck from the docs, the lodash/fp round has a fixed arity of one, meaning it only takes a single argument.

It’s not clear to me if the behavior provided by that second arg is available in fp. I guess it isn’t?

@falsyvalues
Copy link
Contributor

falsyvalues commented Nov 5, 2019

Hi @shauntck!

Like @jamesplease said methods like round have a fixed arity of one. You can customize them with convert.

@L2jLiga I hope @jamesplease response was clear, if not feel free to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants