0

ngx-mask specific question!

Is there a way to allow user to input comma and dot as a decimal marker, but keep the dot in displayed value and then trim thousand separators?

User inputs "123456,78", sees "123 456.78", value is "123456,78"
User inputs "123456.78", sees "123 345.78", value is "123456.78"

Cant find any way to achieve this result with ngx-mask

Thanks in advance!

Update: seems stackoverflow needs some debugging but I have zero clue what info is needed cuz I just dont see any way I can achieve this functionality. Ok, I'll show what I tried.

I tried custom patterns, like this:

customPatterns = {
    D: {
      pattern: new RegExp('[,.]'),
      symbol: '.',
    },
    0: { pattern: new RegExp('\\d') },
  };

...

[mask]='0*D00'

But symbol doesnt work for some reason, comma stays displayed if you input it

And I tried something like [mask]="'0*(,|.)00'", but it doesnt work at all

lucifer63
  • 704
  • 7
  • 26

1 Answers1

0

answer : In React, how to format a number with commas?

number.toLocaleString(); // "1,234,567,890"

// A more complex example: 
var number2 = 1234.56789; // floating point example
number2.toLocaleString(undefined, {maximumFractionDigits:2}) // "1,234.57"