0

I have input text field in angular, that converts large value to 5.5E9. When the value is supposed to show - 5500000000

Here is the input field:

<input [(ngModel)]="sck" 
                   name="cap1" [pattern]="checkPattern"
                    placeholder="cap" type="text"
                    class="ng-untouched ng-pristine ng-valid"  #uname="ngModel">

Here is the check pattern in the ts

this.checkPattern = "^[0-9]*$"; 

Please how do I prevent the exponential value in the input field

Blaze
  • 2,269
  • 11
  • 40
  • 82
  • 1
    Side note: you shouldn't add `ng-untouched ng-pristine ng-valid` css classes. Angular adds it itself. You may also use a formControl instead. – Random Aug 06 '20 at 12:35
  • why does angular adds it and angularjs does not add it – Blaze Aug 06 '20 at 12:44
  • 1
    Does this answer your question? [How to avoid scientific notation for large numbers in JavaScript?](https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript) – Heretic Monkey Aug 06 '20 at 13:00

1 Answers1

0

Add number pipe to [(ngModel)] in a following way:

<input 
  [ngModel]="sck | number:'1.0-8'" 
  (ngModelChange)="sck = $event"                 
  name="cap1" 
  [pattern]="checkPattern"
  placeholder="cap" 
  type="text"
  #uname="ngModel" />

[ngModel] will format it fine and (ngModelChange) will take care of assignment.

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63