我想格式化一个数字,以显示小数的罗马尼亚格式和数千像这样:1.000,23 . 我正在使用numeral.js库 . 这是我的管道代码:
constructor(private session: SessionService) {
numeral.register('locale', 'ro', {
delimiters: {
thousands: this.session.Settings.groupSymbols,
decimal: this.session.Settings.decimalSymbols
},
abbreviations: {
thousand: 'k',
million: 'm',
billion: 'b',
trillion: 't'
},
ordinal: function (number) {
return number === 1 ? 'er' : 'ème';
},
currency: {
symbol: 'RON'
}
});
numeral.locale("ro");
}
public transform(value: string) {
var b = numeral(value);
var x = "0,0.";
for (var i = 0; i < this.session.Settings.decimalDigits; i++) {
x = x + "0";
}
return b.format(x);
这是显示的标签输出:
<label>{{ '12345678' | decimalUnitPipe }}</label>
<br>
<label>{{ '1.234,5678' | decimalUnitPipe }}</label>
<br>
<label>{{ '1,234.5678' | decimalUnitPipe }}</label>
<br>
<label>{{ '1,2345678' | decimalUnitPipe }}</label>
<br>
<label>{{ '1.2345678' | decimalUnitPipe }}</label>
这是浏览器向我显示的输出:
12,345,678.00
1.23
1,234.57
12,345,678.00
1.23
如何转换我的本地以在标签中以所需格式显示我的数字 . 在第一个数字上它还显示小数(.00),如果我没有在其中放入任何小数,我不希望它们显示 . 在第二个中它显示:1.23我希望它显示:1.234,5678等
请帮助,提前谢谢!