javascript - String to Number conversion is not working -
i have input below. can see converts budget
numeric
property thousands separators (e.g. 1,000
).
<ion-input [ngmodel]="project.budget | thousandsseparatorpipe" (ngmodelchange)="project.budget=$event;calculatecontingency()" formcontrolname="budget" type="text"></ion-input>
here not working:
calculatecontingency(eve:any) { this.project.contingency = ((number(this.project.budget) * this.project.contingencypercentage) * 1 / 100); this.changedetectorref.detectchanges(); }
it shows this:
can tell me how sort out issue? or how can use budget
model without thousand separators? if can can send above calculation method no.
use parsefloat
regex replace comma,
this.project.contingency = ((parsefloat(this.project.budget.replace(/,/g, '')) * this.project.contingencypercentage) * 1 / 100);
demo
var budget = '1,000'; var buget2 = 1000; var contigency = parsefloat(budget.replace(/,/g, '')) + buget2; console.log(contigency);
Comments
Post a Comment