ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

Thousand Separator doesn't work correctly with some locales

Open igor-chernetsky opened this issue 3 years ago • 1 comments

Description

Looks like separator doesn't work for browsers with locale, where decimal delimiter is , it just show numbers like 1.22 as 122 mask="separator" thousandSeparator="."

🔬 Minimal Reproduction

the quick fix it just set up static locale

	public numberToString(value: number | string): string {
		if (!value && value !== 0) {
			return String(value);
		}
		return Number(value).toLocaleString('**en-US**', {
			useGrouping: false,
			maximumFractionDigits: 20,
		});
	}

but probably additional attribute like [locale-separator] would be useful

igor-chernetsky avatar Jun 10 '22 17:06 igor-chernetsky

Was just going to open issue for this, but I have the exact same problem. In our app, we always use ',' for thousandSeparator and '.' for decimal separator (I do have them specified in ngx-mask cfg)

But the piece of code from the OP messes up our number inputs for user that dont have a local where these are the default (like fr-CA, that has '(space)' for thousand separator and ',' for decimalSeparator)

Let's say we have the string '7.5' for our data that we want to display as 7.50 (separator.2) It use to be (in version 12.xxx) that the mask directive would leave our value intact image And then display it correctly

But now in v13+, it tries to convert it because of the 'separator.2' image

It calls maskService.numberToString (the piece of code OP linked) and transforms '7.5' to '7,5', which ends up as '75' in the input image

So we would need for this transformation to stop happening, or numberToString to take into account the specified thousandSeparator and decimalSeparator.

This can be tested by settings other languages in chrome (like french (france) or french (canada) chrome://settings/?search=lang

gabrielgagne avatar Jun 14 '22 18:06 gabrielgagne

Does using decimalMarker="," fix your issue?

daniel-seitz avatar Sep 30 '22 11:09 daniel-seitz

see also https://github.com/JsDaddy/ngx-mask/issues/1009#issuecomment-1291920468, might help?

mrpia avatar Oct 26 '22 12:10 mrpia

@igor-chernetsky Thanks for your using Ngx-Mask. Please update to latest version. It example, all work as expected - https://stackblitz.com/edit/angular-7dxc1z?file=src%2Fmain.ts

andriikamaldinov1 avatar Jun 20 '23 10:06 andriikamaldinov1