/*---------------------------------------------------------
Description:
Demonstrates how to represent and display currency
values in idiomatic JavaScript using Intl.NumberFormat.
---------------------------------------------------------*/
const usd = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD"
});
// Price and tax rate
const price = 199.99;
const taxRate = 0.17; // 17%
// Calculate tax and total
const taxAmount = price * taxRate;
const total = price + taxAmount;
// Output with $ and % signs
console.log("Price: " + usd.format(price));
console.log("Tax Rate: 17%");
console.log("Tax Amount: " + usd.format(taxAmount));
console.log("Total: " + usd.format(total));
/*
run:
Price: $199.99
Tax Rate: 17%
Tax Amount: $34.00
Total: $233.99
*/