Use intl format for numbers

This commit is contained in:
dangered wolf 2024-04-29 23:17:16 -04:00
parent d912125a78
commit af07eca64e
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58

View file

@ -201,7 +201,7 @@ const generateStatusFooter = (status: APIStatus, isQuote = false, author: APIUse
}; };
const generatePoll = (poll: APIPoll, language: string): string => { const generatePoll = (poll: APIPoll, language: string): string => {
// const formatNumber = Intl.NumberFormat(language ?? 'en') const intlFormat = Intl.NumberFormat(language ?? 'en');
let str = ''; let str = '';
const barLength = 20; const barLength = 20;
@ -209,10 +209,10 @@ const generatePoll = (poll: APIPoll, language: string): string => {
poll.choices.forEach(choice => { poll.choices.forEach(choice => {
const bar = '█'.repeat((choice.percentage / 100) * barLength); const bar = '█'.repeat((choice.percentage / 100) * barLength);
// eslint-disable-next-line no-irregular-whitespace // eslint-disable-next-line no-irregular-whitespace
str += `${bar}<br>${choice.label}<br>${choice.count} votes, ${choice.percentage}%<br>`; str += `${bar}<br>${choice.label}<br>${intlFormat.format(choice.count)} votes, ${intlFormat.format(choice.percentage)}%<br>`;
}); });
/* Finally, add the footer of the poll with # of votes and time left */ /* Finally, add the footer of the poll with # of votes and time left */
str += `<br>${formatNumber(poll.total_votes)} votes · ${poll.time_left_en}`; str += `<br>${intlFormat.format(poll.total_votes)} votes · ${poll.time_left_en}`;
return str; return str;
}; };