MCPcopy Create free account
hub / github.com/dailydotdev/apps / largeNumberFormat

Function largeNumberFormat

packages/shared/src/lib/numberFormat.ts:3–27  ·  view source on GitHub ↗
(value: number)

Source from the content-addressed store, hash-verified

1import type { PaddleProductLineItem } from '../graphql/paddle';
2
3export function largeNumberFormat(value: number): string | null {
4 if (typeof value !== 'number') {
5 return null;
6 }
7 let newValue = value;
8 const suffixes = ['', 'K', 'M', 'B', 'T'];
9 let suffixNum = 0;
10 while (newValue >= 1000) {
11 newValue /= 1000;
12 suffixNum += 1;
13 }
14 if (suffixNum > 0) {
15 const remainder = newValue % 1;
16 // If the remainder is very small (< 0.05), show no decimal places
17 // If the remainder is significant, show one decimal place
18 const decimalPlaces = remainder >= 0 && remainder < 0.05 ? 0 : 1;
19 const roundedValue =
20 Math.round(newValue * 10 ** decimalPlaces) / 10 ** decimalPlaces;
21 // Check if the rounded value is a whole number
22 const isWholeNumber = roundedValue % 1 === 0;
23 const finalDecimalPlaces = isWholeNumber ? 0 : decimalPlaces;
24 return roundedValue.toFixed(finalDecimalPlaces) + suffixes[suffixNum];
25 }
26 return newValue.toString();
27}
28
29export const getRandom4Digits = (leftPad?: string): string => {
30 const random = Math.floor(1000 + Math.random() * 9000);

Callers 15

ReputationUserBadgeFunction · 0.90
InteractionCounterFunction · 0.90
RepostListItemFunction · 0.90
IntroScreenFunction · 0.90
ItemFunction · 0.90
SquadItemFunction · 0.90
HeaderFunction · 0.90
ProfileButtonFunction · 0.90
DevCardStatsSectionFunction · 0.90
SquadMemberShortListFunction · 0.90
SquadStatFunction · 0.90
SidebarProfileStatsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected