From 331da87bd53bc1fb79063d142764c75df9f32170 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 14 Mar 2018 12:19:54 -0400 Subject: tests --- frontend/lib/formatMoney.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'frontend/lib') diff --git a/frontend/lib/formatMoney.js b/frontend/lib/formatMoney.js index edddf48..301f01f 100644 --- a/frontend/lib/formatMoney.js +++ b/frontend/lib/formatMoney.js @@ -1,3 +1,11 @@ -export default function(amount) { - return '$' + (amount / 100).toLocaleString(); +export default function (amount) { + const options = { + style: 'currency', + currency: 'USD', + minimumFractionDigits: 2, + }; + // if its a whole, dollar amount, leave off the .00 + if (amount % 100 === 0) options.minimumFractionDigits = 0; + const formatter = new Intl.NumberFormat('en-US', options); + return formatter.format(amount / 100); } -- cgit v1.3