1
0
mirror of https://github.com/whippyshou/mastodon synced 2025-01-23 02:04:36 +09:00
This commit is contained in:
whippyshou 2024-01-17 00:19:24 +09:00
parent 06ef2bb8ea
commit 9de2ebcde2
2 changed files with 22 additions and 31 deletions

View File

@ -56,29 +56,21 @@ const ShortNumberCounter: React.FC<ShortNumberCounterProps> = ({ value }) => {
const values = { count, rawNumber };
switch (unit) {
case DECIMAL_UNITS.THOUSAND: {
values.rawNumber = values.rawNumber*1000
return (
<FormattedMessage
defaultMessage='{rawNumber}'
values={values}
/>
);
}
case DECIMAL_UNITS.MILLION: {
values.rawNumber = values.rawNumber*10000
return (
<FormattedMessage
defaultMessage='{rawNumber}'
id='units.short.million'
defaultMessage='{count}M'
values={values}
/>
);
}
case DECIMAL_UNITS.BILLION: {
values.rawNumber = values.rawNumber*100000
return (
<FormattedMessage
defaultMessage='{rawNumber}'
id='units.short.billion'
defaultMessage='{count}B'
values={values}
/>
);

View File

@ -24,24 +24,23 @@ export type ShortNumber = [number, DecimalUnits, 0 | 1]; // Array of: shorten nu
* // => [5.936, 1000, 1]
*/
export function toShortNumber(sourceNumber: number): ShortNumber {
if (sourceNumber < DECIMAL_UNITS.THOUSAND) {
return [sourceNumber, DECIMAL_UNITS.ONE, 0];
} else if (sourceNumber < DECIMAL_UNITS.MILLION) {
return [
sourceNumber / DECIMAL_UNITS.THOUSAND,
DECIMAL_UNITS.THOUSAND,
sourceNumber < TEN_THOUSAND ? 1 : 0,
];
} else if (sourceNumber < DECIMAL_UNITS.BILLION) {
return [
sourceNumber / DECIMAL_UNITS.MILLION,
DECIMAL_UNITS.MILLION,
sourceNumber < TEN_MILLIONS ? 1 : 0,
];
} else if (sourceNumber < DECIMAL_UNITS.TRILLION) {
return [sourceNumber / DECIMAL_UNITS.BILLION, DECIMAL_UNITS.BILLION, 0];
}
// if (sourceNumber < DECIMAL_UNITS.THOUSAND) {
// return [sourceNumber, DECIMAL_UNITS.ONE, 0];
// } else if (sourceNumber < DECIMAL_UNITS.MILLION) {
// return [
// sourceNumber / DECIMAL_UNITS.THOUSAND,
// DECIMAL_UNITS.THOUSAND,
// sourceNumber < TEN_THOUSAND ? 1 : 0,
// ];
// } else if (sourceNumber < DECIMAL_UNITS.BILLION) {
// return [
// sourceNumber / DECIMAL_UNITS.MILLION,
// DECIMAL_UNITS.MILLION,
// sourceNumber < TEN_MILLIONS ? 1 : 0,
// ];
// } else if (sourceNumber < DECIMAL_UNITS.TRILLION) {
// return [sourceNumber / DECIMAL_UNITS.BILLION, DECIMAL_UNITS.BILLION, 0];
// }
return [sourceNumber, DECIMAL_UNITS.ONE, 0];
}