Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I subtract a percentage from a number in a string?

Tags:

javascript

var valueInString = "2383";

How do I subtract 35% from number and put it back in the variable?

valueInString = valueInString - 35% 

Something like the above?

like image 728
Gast1 Avatar asked May 22 '13 12:05

Gast1


People also ask

How do you subtract a percentage from a number in Excel?

Tip: You can also multiply the column to subtract a percentage. To subtract 15%, add a negative sign in front of the percentage, and subtract the percentage from 1, using the formula =1-n%, in which n is the percentage. To subtract 15%, use =1-15% as the formula.

Can you just subtract percentages?

To subtract a percent from a percent, simply ignore the percent sign and subtract the numbers as if they were whole numbers. The result will be a difference in percentage points.

How can we calculate percentage?

To determine the percentage, we have to divide the value by the total value and then multiply the resultant by 100.


2 Answers

If I understand you correctly, you want to subtract 35% of valueInString from valueInString. So it is just some basic math.

var valueInString = "2383";
var num = parseFloat(valueInString);
var val = num - (num * .35);
console.log(val);
like image 181
epascarello Avatar answered Nov 01 '22 12:11

epascarello


Math:

valueInString = valueInString * (1 - 0.35);

Shorter:

valueInString *= 1 - 0.35;
like image 33
Ry- Avatar answered Nov 01 '22 13:11

Ry-