Compare localized decimal in Angular

I use i18nfor my application. I currently have a column with a decimal value.

For enit will be 0.10. For frit is 0.10.

My problem is comparing this column with an integer.

return myDecimalValue < 5;

Now this works fine for en, but does not work on fr. Is there a way to format the decimal value so that I can correctly compare it with an integer?

+4
source share
1 answer

Wih previous version (2.x), I used the custom channel whick uses .toLocaleString().

@Pipe({ name: 'format' })
export class NumberFormatter implements PipeTransform {
    transform(_number: any, lang: string) {
        if (_number) {
            let floatNumber = parseFloat(_number);
            let lang = "fr-FR";
            if (!lang || lang == "fr") {
                lang = "fr-FR";
            } else if (lang == "en") {
                lang = "en-US";
            }
            return floatNumber.toLocaleString(lang);
        }
    }
}

And look at the template:

<p>{{ decimal | format:'en' }}</p>
0
source

Source: https://habr.com/ru/post/1695746/


All Articles