1
0
mirror of https://github.com/whippyshou/mastodon synced 2025-01-23 10:14:43 +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 }; const values = { count, rawNumber };
switch (unit) { switch (unit) {
case DECIMAL_UNITS.THOUSAND: {
values.rawNumber = values.rawNumber*1000
return (
<FormattedMessage
defaultMessage='{rawNumber}'
values={values}
/>
);
}
case DECIMAL_UNITS.MILLION: { case DECIMAL_UNITS.MILLION: {
values.rawNumber = values.rawNumber*10000
return ( return (
<FormattedMessage <FormattedMessage
defaultMessage='{rawNumber}' id='units.short.million'
defaultMessage='{count}M'
values={values} values={values}
/> />
); );
} }
case DECIMAL_UNITS.BILLION: { case DECIMAL_UNITS.BILLION: {
values.rawNumber = values.rawNumber*100000
return ( return (
<FormattedMessage <FormattedMessage
defaultMessage='{rawNumber}' id='units.short.billion'
defaultMessage='{count}B'
values={values} values={values}
/> />
); );

View File

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