gastonmesseri / numerable

Number formatting library for Javascript and Node.js apps
MIT License
84 stars 1 forks source link

Don't abbreviate if the result is the same length or longer #4

Closed DanielBreiner closed 2 years ago

DanielBreiner commented 2 years ago

It doesn't make sense to abbreviate 1000 to 1.000k

gastonmesseri commented 2 years ago

Hi @DanielBreiner,

The amount of decimal places you want to display is up to you. The strategy for abbreviation is fixed, so, if the number is bigger or equal than the abbreviation stop, it will be abbreviated.

Given what you described, I assume you are using something like the following: format(1000, '0.000a') // Returns "1.000k" It that is the case, it returns "1.000k" because you explicitly requested having 3 decimal places.

You can instead do the following: format(1000, '0.###a') // Returns "1k" In this case, we are defining "up to 3 optional decimal places". So, maybe this approach is better for you.

If you have any solid suggestion for abbreviation strategies, let me know, so that I can take that into consideration.

Gastón

DanielBreiner commented 2 years ago

Alright, but what about abbreviateing 1234 to 1.234k? This kind of abbreviation makes the number longer and way less readable. Is there a way to keep 1234 as 1234 but abbreviate 12345 to 12.345k?