'Displaying javascript calculated variable output as currency
I currently have a variable that is made up of two calculated variables. How ever I need to display the outputted variable as a currency which includes thousand separators.
In this instance, the user inputs the width and length of a room and then the java calculates and tells the user how much the required quantity will be. I will add my code below to help see how this is currently working.
All help would be greatly appreciated. Thanks
Here is the calculation variable:
$price = ($quantity_needed*pricePerTile);
$('#ft-price-res').text("£"+$price.toFixed(3));
The full javascript for this page you can view here: https://jsfiddle.net/3yw4m7kj/
Solution 1:[1]
e.g.:
$('#ft-price-res').text(Intl.NumberFormat('en-GB', {
style:'currency',
currency:'GBP',
minimumFractionDigits:3
}).format($price));
and fairly safe to use : https://caniuse.com/?search=Intl.NumberFormat
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | bknights |