diff --git a/components/item-full.js b/components/item-full.js index 39765216..dbcfead7 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -150,7 +150,7 @@ function TopLevelItem ({ item, noReply, ...props }) { ) : (
- {numWithUnits(item.bounty, { abbreviate: false })} bounty + {numWithUnits(item.bounty, { abbreviate: false, format: true })} bounty
)} } diff --git a/lib/format.js b/lib/format.js index 2bcd0763..ebcc0519 100644 --- a/lib/format.js +++ b/lib/format.js @@ -15,16 +15,18 @@ export const abbrNum = n => { * @param opts.abbreviate Whether to abbreviate the number * @param opts.unitSingular The singular unit label * @param opts.unitPlural The plural unit label + * @param opts.format Format the number with `Intl.NumberFormat`. Can only be used if `abbreviate` is false */ export const numWithUnits = (n, { abbreviate = true, unitSingular = 'sat', - unitPlural = 'sats' + unitPlural = 'sats', + format = false } = {}) => { if (isNaN(n)) { return `${n} ${unitPlural}` } - return `${abbreviate ? abbrNum(n) : n} ${n === 1 ? unitSingular : unitPlural}` + return `${abbreviate ? abbrNum(n) : format ? new Intl.NumberFormat().format(n) : n} ${n === 1 ? unitSingular : unitPlural}` } export const fixedDecimal = (n, f) => {