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

Math:

valueInString = valueInString * (1 - 0.35);

Shorter:

valueInString *= 1 - 0.35;

A nice little utility function for this would be:

const percentageOff = (
  price: number,
  percentageValue: number
): number => {
  return price * (1 - percentageValue / 100)
}

percentageOff(100, 50); // Output: 50

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);

Tags:

Javascript