【发布时间】:2019-02-21 18:49:04
【问题描述】:
我一直在尝试根据国家/地区更改 AngularJS 应用程序中的数字,并使用以下函数在整个应用程序中使用 .toLocaleString 函数
numberValueTransformation(value) {
if (value === 0 || value === undefined) {
return 0;
}
const currencyLocale = this.UserPreferences.getCountryLocale().replace(/fr-FR/g, 'de-DE');
const currencyCode = this.UserPreferences.getCountryCode();
return Number(value).toLocaleString(currencyLocale, {
// style: 'currency',
currency: currencyCode,
minimumFractionDigits: 2
});
}
上面的函数工作得很好,但我需要在整个应用程序的括号中显示负值。我们可以修改.toLocaleString 以获得括号中的负值还是我需要手动更改整个应用程序?
我得到的价值是 123456689 美元。但是如果是负值,我得到 -$123456789,但这里我希望值为 ($123456789)
【问题讨论】:
-
“括号中的负值”是什么意思?
-
@RokoC.Buljan 我认为他的意思是括号;即,“(100)”表示-100。
-
是的,我的意思是一样的!
-
这些没有内置方法。请参阅How can I format numbers as dollars currency string in JavaScript? 进行一些尝试。
-
只是出于好奇,何时以及为什么要将负数放入字符串、正数和括号内?
标签: javascript angularjs ecma