billing-helpers: Add commas to formatted amount.

This commit is contained in:
sbansal1999
2023-04-30 11:41:22 +05:30
committed by Tim Abbott
parent 263ee4cb86
commit 7c68a30363
2 changed files with 10 additions and 6 deletions

View File

@@ -75,8 +75,10 @@ export function format_money(cents) {
} else { } else {
precision = 2; precision = 2;
} }
// TODO: Add commas for thousands, millions, etc. return new Intl.NumberFormat("en-US", {
return (cents / 100).toFixed(precision); minimumFractionDigits: precision,
maximumFractionDigits: precision,
}).format((cents / 100).toFixed(precision));
} }
export function update_charged_amount(prices, schedule) { export function update_charged_amount(prices, schedule) {

View File

@@ -188,8 +188,8 @@ run_test("format_money", () => {
assert.equal(helpers.format_money("666.6666666666666"), "6.67"); assert.equal(helpers.format_money("666.6666666666666"), "6.67");
assert.equal(helpers.format_money("7600"), "76"); assert.equal(helpers.format_money("7600"), "76");
assert.equal(helpers.format_money("8000"), "80"); assert.equal(helpers.format_money("8000"), "80");
assert.equal(helpers.format_money("123416.323"), "1234.17"); assert.equal(helpers.format_money("123416.323"), "1,234.17");
assert.equal(helpers.format_money("927268238"), "9272682.38"); assert.equal(helpers.format_money("927268238"), "9,272,682.38");
}); });
run_test("update_charged_amount", () => { run_test("update_charged_amount", () => {
@@ -198,11 +198,13 @@ run_test("update_charged_amount", () => {
prices.monthly = 800; prices.monthly = 800;
page_params.seat_count = 35; page_params.seat_count = 35;
// 80 * 35 = 2800
helpers.update_charged_amount(prices, "annual"); helpers.update_charged_amount(prices, "annual");
assert.equal($("#charged_amount").text(), (80 * 35).toString()); assert.equal($("#charged_amount").text(), "2,800");
// 8 * 35 = 280
helpers.update_charged_amount(prices, "monthly"); helpers.update_charged_amount(prices, "monthly");
assert.equal($("#charged_amount").text(), (8 * 35).toString()); assert.equal($("#charged_amount").text(), "280");
}); });
run_test("show_license_section", () => { run_test("show_license_section", () => {