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:

enter image description here

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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -