-2

I'm trying to make a calculation functions that take a string value converts it into a float with 2 decimal points then calculate it by increasing the original value by 10% and then return it as a string. However I'm getting the return value incorrectly.

function updatePoints(points: string):string{
    const intPoints = parseFloat(points).toFixed(2)
    const totalPoints = (((+intPoints/100)*10)+intPoints)
    console.log(totalPoints)
    return totalPoints
}

if i input 1000, I'm expecting a value to return 1100. However I'm getting 1001000.00, which are added up with 2 strings instead.

Philip Teng
  • 67
  • 1
  • 7

1 Answers1

-1

Like this?

updatePoints(points: string):string{
  const floatPoints: number = parseFloat(points);
  const totalPoints = (floatPoints + floatPoints * 0.1).toFixed(2);
  console.log(totalPoints)
  return totalPoints
}
arnonuem
  • 1,317
  • 6
  • 19