1

In my JSX, I'm mapping through API data and then display the values, from the object array.

Except in my JSX, I want to add two prices together, from my data. Something like this.

<div className="right">
  <p>
    from <span>£{(phone.priceInfo.hardwarePrice.oneOffPrice.gross + phone.priceInfo.hardwarePrice.oneOffPrice.gross)}</span> upfront cost
  </p>
</div>

However, let's say phone.priceInfo.hardwarePrice.oneOffPrice.gross === 10, then in my DOM, the following returns £10+£10, rather than £20.

How do I do an addition sum, in my JSX?

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Reena Verma
  • 1,617
  • 2
  • 20
  • 47
  • Answered - duplicate here https://stackoverflow.com/questions/4841373/how-to-force-js-to-do-math-instead-of-putting-two-strings-together – Reena Verma Aug 19 '18 at 19:36
  • remember that input received from HTML elements is _always_ string data. If you need numbers, use `parseFloat` before you do things that assume numbers (rather than `parseInt`). – Mike 'Pomax' Kamermans Aug 19 '18 at 19:37

0 Answers0