I want to format a number to also display the Romanian format for decimals and thousands like this: 1.000,23 . I am using the numeral.js
library.
Here is my pipe code:
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);
}
This is the tags output displayed:
<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>
And this is the output displayed by the browser:
12,345,678.00
1.23
1,234.57
12,345,678.00
1.23
How can I convert my local to display my numbers in the wanted format like in the label? On the first number, it also displays the decimals (.00)
and I do not want them to be displayed if I do not put any decimals in there. In the second one, it shows 1.23
and I want it to show 1.234,5678
etc.
Please help, thanks in advance!