Miyer
Miyer

Reputation: 365

This script answer doesn't do the math as expected

I'm facing a problem with adition to the below coding where I'm getting the wrong answer

e.g. 50,000 + 23,314 = 73,314 but I'm getting an answer as 733 (the first three digits of the answer) where did I go wrong in the below code?

function doStuff() {
  const rate = 0.155;

  const period = 12;// add motnhs here
  const opp = vprice*0.5;
  var nf = new Intl.NumberFormat(); //number format 
 
 const subL = nf.format(Math.round((vprice*0.15)/2));
  
  const res =  nf.format(Math.round ((vprice - downPayment) * rate / period));
 
 const YearBulk1 = parseInt(subL)+ parseInt(res); //getting partial answer.
      

Upvotes: 0

Views: 42

Answers (1)

Mark Taylor
Mark Taylor

Reputation: 1188

the issue here is commas in your strings prior to the parsing. You can remove them as per the snippet below.

 let stringValue = "3,750";
 console.log(stringValue);
 console.log(parseInt(stringValue));
 console.log(parseInt(stringValue.replace(",", "")));
 

Upvotes: 2

Related Questions