Skip to content

Commit

Permalink
docs: add some jsdoc to formatNum
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Dec 22, 2022
1 parent 7b63e98 commit c15c9b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/formatNum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const intlCurrencyFmt = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
const intlPercentageFmt = new Intl.NumberFormat("en-US", { style: "percent" });

/**
* These methods take as an argument a *WHOLE* integer (do not include any decimal places)
* and returns a string representation based on expected units using the `en-US` locale.
*
* - toCurrencyStr `123456` becomes `"$1,234.56"`
* - toPercentageStr `123` becomes `"123%"`
*/
export const formatNum = {
toCurrencyStr: (num: number) => intlCurrencyFmt.format(num),
toCurrencyStr: (num: number) => intlCurrencyFmt.format(num / 100),
toPercentageStr: (num: number) => intlPercentageFmt.format(num)
};

0 comments on commit c15c9b3

Please sign in to comment.