In the example below, the correct calculation is performed, but for some unknown reason p.calcPrice
ends up being a string. It should ideally be a number since using .toFixed()
on a string doesn't make sense.
When I refer to p.calcPrice
, do I need to explicitly convert it using +p.calcPrice
? Or is there a way for TypeScript to recognize it as a number so that casting is not required?
p.calcPrice = (
price *
+p.amount *
(1 - pD / 100) *
(1 - mD / 100)
).toFixed(2);