I'm creating a new textbox to accept numbers with decimals in my web application using Angular 5. But I see that Angular is changing one particular number which is 31.74 to 31.73. How to keep my current number?
My application is built using Asp.Net MVC 5, Angular 5, C#, SQL Database.
<input name="txtTEST" type="text" style="width: 120px; text-align: right;" maxlength="15" tabindex="1" [disabled]="!isEnableTest" [ngModel]="test|number:'1.2-2'" (ngModelChange)="ModelOnChange($event, 'tst')" [ngModelOptions]="{updateOn: 'blur'}" />
I expect the output of 31.74 to be 31.74. But the actual output is 31.73.
-------Solved-------
I'm dividing 31.74 by 100 (which should give me 0.3174) in Angular and it becomes 0.31739999. This number is rounded to 31.73 when I pass it to my C# code.
So in Angular instead of dividing by 100 I changed the code to:
k.aTest = (this.test * 100) / 10000;
And problem solved.
-------------STILL THIS ISSUE IS THERE-------
It is randomly happening based on numbers.