I have a basic page with a cart-like system written in JS.
I'd like to format the numbers shown as a currency, using Intl.NumberFormat to make the prices readable according to the users locale if possible.
Having a very basic knowledge of JS, i have made various attempts without success, partial code looks like this:
$('.price').html(set_price.toFixed(2));
I have attempted to modify the above code to this:
$('.price').html(Intl.NumberFormat('de-DE').format(parseFloat(set_price.toFixed(2))));
But it doesn't work, because the number produced by the above code is used for other calculations in the page (for example, if quantity changes it add/substracts the number, resulting in calculation errors.)
The totals are shown in the front end inside a div such as this one:
<div class="price">0</div>
Where it dinamically updates the number as items are added/substracted.
Is there a way to format the number shown, without obstructing its calculation capabilities?