-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Use-case:
I'd like to round negative values but I don't want -0 to be formatted into a string with "minus" sign i.e. I prefer "0" instead of "-0"
For example:
const formatter = new Intl.NumberFormat("en", {
maximumFractionDigits: 1
});
console.log(formatter.format(-0.03));
// Returns: -0
// Desired result: 0The proposed spec for signDisplay supports these options: auto, always, never and exceptZero. But, none of them seem to produce the output desired for the use-case above - without compromising on something else.
exceptZero comes close, but in addition to removing the minus sign from -0, it also adds a plus sign to positive numbers (as expected) which is not desired for the use-case above.
var formatter = new Intl.NumberFormat("en", {
maximumFractionDigits: 1,
signDisplay: "exceptZero"
});
console.log(formatter.format(-0.03));
// Returns the desired result: 0 👍
// but...
console.log(formatter.format(123));
// Returns: +123 👎
// Desired result: 123I found this table containing examples of signDisplay options here: https://github.com/tc39/proposal-unified-intl-numberformat/blob/master/README.md#iii-sign-display. I was hoping to find an option that would produce -1 | 0 | 0 | 1 | NaN, but such an option does not seem to exist.
Am I missing something? What is the recommendation for handling the use-case above?
Thank you.