My application accepts different language. I have German language preferred by user and have it registered using registerLocale. I am able to convert the DB decimal values - 0.001 (en-fromat) to 0,001 (de format)
But now when the user has entered any number/ decimal in their regional format then I need to change that from 0,001 (de format) to 0.001 (en format) so that the correct data is stored in the DB.
I have tried following -
console.log(this.value.toLocaleString('de-DE')); -- doesnt work
console.log(new Intl.NumberFormat('de-DE').format(this.value)); --give NaN
new Intl.NumberFormat(locale, {minimumFractionDigits: 5}).format(Number(value)); - gives NaN
console.log('formatNumber-' + this.LocalNumberPipe.transform(value)); -- give NaN
I am not understanding how to resolve this. Is there any generic way. I am looking for a way which will help me in converting any locale to EN-US as German locale is one such example.
My localNumberPipe is
@Pipe({
name: 'localNumber',
})
export class LocalNumberPipe implements PipeTransform {
constructor(private session: SessionService) { }
transform(value: any, format?: string) {
if (value == null) { return ''; } // !value would also react to zeros.
if (!format) { format = '.2-2'; }
return formatNumber(value, this.session.locale, format);
}
}
Please, do any one have any idea on how can i solve this.