How to add a currency symbol at right if the input is € or left is the input is $? Is there a pipe for it or something else?
That is the pipe I wrote but the user can enter letter that is what I want to avoid, or 000.
transform(value: unknown, currencySymbol: string):unknown {
let stringValue = <string>value;
if (!stringValue) {
stringValue = currencySymbol + ' 0';
}
if (stringValue.charAt(0) === currencySymbol) {
return currencySymbol + ' ' + stringValue.replace(currencySymbol, '').trim();
} else
{
return currencySymbol + ' ' + value;
}
}
The Angular currency pipe already does that based on locale data. In order to use it, you need to add the localize features first:
Then, you have to register all the locales you need in app.module.ts. Note that the register function has to be called directly (not inside the module constructor):
You can use the currency pipe like this:
Output:
Remarks: