I'm trying to create a function that converts two strings to a float value.
Some external party created a theme with a backend where you should provide to values for a price:
- priceBeforeComma
- priceAfterComma
In the html this converts to:
<span>55,<sup>07</sup></span>
I need to do some calculations with the price as a float before splitting it up again for the html like you can see above.
I have a function that works pretty fine:
function parsePrice(price, priceDecimal) {
return parseFloat(price + "." + priceDecimal);
}
However, the problem I'm facing is that let's say I provide 07
as the decimal like above, the leading zero is removed, returning 55,7
.
There is quite a big difference between 55,07
and 55,7
. I expect to get back the zero as well like 55,07
.
Any help will be much appreciated.