Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing-helpers: Add commas to formatted amount.

sbansal19997c68a303630e
diff --git a/web/src/billing/helpers.js b/web/src/billing/helpers.js
index a5f7592153c..973f53f3c0f 100644
--- a/web/src/billing/helpers.js
+++ b/web/src/billing/helpers.js
@@ -75,8 +75,10 @@ export function format_money(cents) {
} else {
precision = 2;
}
- // TODO: Add commas for thousands, millions, etc.
- return (cents / 100).toFixed(precision);
+ return new Intl.NumberFormat("en-US", {
+ minimumFractionDigits: precision,
+ maximumFractionDigits: precision,
+ }).format((cents / 100).toFixed(precision));
}
export function update_charged_amount(prices, schedule) {
diff --git a/web/tests/billing_helpers.test.js b/web/tests/billing_helpers.test.js
index 49fc3db8145..275220b4dfe 100644
--- a/web/tests/billing_helpers.test.js
+++ b/web/tests/billing_helpers.test.js
@@ -188,8 +188,8 @@ run_test("format_money", () => {
assert.equal(helpers.format_money("666.6666666666666"), "6.67");
assert.equal(helpers.format_money("7600"), "76");
assert.equal(helpers.format_money("8000"), "80");
- assert.equal(helpers.format_money("123416.323"), "1234.17");
- assert.equal(helpers.format_money("927268238"), "9272682.38");
+ assert.equal(helpers.format_money("123416.323"), "1,234.17");
+ assert.equal(helpers.format_money("927268238"), "9,272,682.38");
});
run_test("update_charged_amount", () => {
@@ -198,11 +198,13 @@ run_test("update_charged_amount", () => {
prices.monthly = 800;
page_params.seat_count = 35;
+ // 80 * 35 = 2800
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");
- assert.equal($("#charged_amount").text(), (8 * 35).toString());
+ assert.equal($("#charged_amount").text(), "280");
});
run_test("show_license_section", () => {