HubSpot / humanize

A simple utility library for making the web more humane. #hubspot-open-source
MIT License
915 stars 75 forks source link

compactInteger doesn't round correctly? #97

Open pdme opened 6 years ago

pdme commented 6 years ago

Humanize.compactInteger(-44604);

Current result: "-44k"

Expected result: "-45k"

No?

crhallberg commented 6 years ago

It looks like there's a special case that truncates for 0 decimals as opposed to rounding: https://github.com/HubSpot/humanize/blob/master/src/humanize.js#L130

If they took this case out and passed -44604 to the case for 1+ decimals, .toFixed(0) would come out to "-45k".

Since the case exists, I'm assuming this is intentional but inconsistent.