-
Notifications
You must be signed in to change notification settings - Fork 143
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
Format option to suppress decimals when zero #299
Comments
You could use a custom formatter: const formatter = (currency, settings) => {
if (!currency.cents()) {
return currency.value;
}
return currency.value.toFixed(settings.precision);
};
const c = value => currency(value, { formatter }); This is a poor man's version of the formatter as it doesn't take into account decimal or group separators, but you use a variation of the default formatter for your needs. |
Thank you very much for your quick response, @scurker. I see. In that case, then I should also handle all the formatting options that I pass in along with the callback "format", don't I? Because I've already test it, and it doesn't work in a chainable way. With this I mean that I would like to pass in some options, and just tweak the string returned by Is it possible to achieve that? EDIT: maybe that could seem a "dumb question", since I already know the passed in options and can check them once I get the value from By the way, I've found out that, when using comma as
|
Is it as simple as this?
|
Would be great if this is actually added as an option I feel. I modified @TimNZ's answer to allow for cases for the following:
|
Would it be possible to add an option to suppress decimals when they are zero?
I am using
precision: 2
, but I would like not to get decimals when the returned value contains ".00".This options should always consider the value of
precision
to only suppress them when all decimals where zero.The text was updated successfully, but these errors were encountered: