我想将输入类型值转换为逗号分隔数。例如,在我的.html文件中,我的净工资输入值是35000(我在Formbuilder中设置)。如果我键入任何值(例如,>输入= 65000,预期输出=> 65,000)。 那么我想在打字稿中做的所有事情。请帮助我。
<div class="form-group md-form mob selecticon rupee-icon" [ngClass]="{'has-danger':!loanApplyForm.controls['netsalary'].valid && loanApplyForm.controls['netsalary'].touched}">
<label for="netsalary">Net Monthly Salary <span class="asterisk">*</span></label>
<div *ngIf="loanApplyForm.controls['netsalary'].invalid" class="alert-change">*Please enter the monthly salary.</div>
<input (focus)="loanApplyForm.controls['netsalary'].reset()" class="form-control emi-input" id="netsalary" [formControl]="loanApplyForm.controls['netsalary']" type="number">
</div>
这是我的.html文件
答案 0 :(得分:0)
在.html
尝试此代码并将数字转换为逗号分隔值。
<input (focus)="loanApplyForm.controls['netsalary'].reset()" class="form-control emi-input" id="netsalary" [formControl]="numberToCommaSeperate(loanApplyForm.controls['netsalary'])" type="number">
并.ts
添加此功能
numberToCommaSeperate(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}