I have a product page that is fetching products information and displaying the products on the page. The API returns three price points. I have to add them up and display the price rounded down to one decimal. I have a solution already working, but it only works if it's not a whole number.
22.7312
returns 22.7
, but 22.0
returns 22
. I would like to always show one decimal, even if it's a zero. This is my current solution. How can I change it so that it shows the one decimal, even if it's a zero?
Math.floor(
(parseFloat(product.price1['regionalPrice'])
+ parseFloat(product.price2['marketPrice'])
+ parseFloat(product.price3['localPrice'])
) * 10) / 10