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

ngx-mask on input rounding off to nearest

Open Jagan-Rameshbabu opened this issue 4 years ago • 4 comments

🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑

I'm using Angular 11 with Material. For a input field to get $ amount upto (15, 2) from user, I'm using the the below code..,

<input matInput type="text"
       mask="separator.2" thousandSeparator=","
       separatorLimit="100000000000000”
       id="membershipStockMinReq" formControlName="membershipStockMinReq" tabindex="17">

I also have same validation in API with 15 digits and 2 decimals. However, when i enter the input as 999999999999999.99, its getting rounded off and passing 1000000000000000 to API which throwing error. Is there any way to restrict the rounding?

🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑

Jagan-Rameshbabu avatar Nov 03 '21 04:11 Jagan-Rameshbabu

Currently using ngx 11.1.5 version.

Jagan-Rameshbabu avatar Nov 03 '21 04:11 Jagan-Rameshbabu

https://javascript.info/number#imprecise-calculations It's a limitation of JS. I would recommend using a string.

BGBRWR avatar Nov 09 '21 19:11 BGBRWR

This is a duplication of https://github.com/JsDaddy/ngx-mask/issues/929

BGBRWR avatar Nov 09 '21 19:11 BGBRWR

https://javascript.info/number#imprecise-calculations It's a limitation of JS. I would recommend using a string.

I dont get you. I'm already using input type as "text".. What else I can do to make it work on the above code?

Jagan-Rameshbabu avatar Nov 16 '21 07:11 Jagan-Rameshbabu

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

andriikamaldinov1 avatar Jun 13 '23 10:06 andriikamaldinov1