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

Function largeNumberFormat

packages/shared/src/lib/numberFormat.ts:3–21  ·  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 const suffixes = ['', 'K', 'M', 'B', 'T'];
8 let suffixNum = 0;
9 while (
10 Math.abs(value) >= 1000 ** (suffixNum + 1) &&
11 suffixNum < suffixes.length - 1
12 ) {
13 suffixNum += 1;
14 }
15 if (suffixNum === 0) {
16 return value.toString();
17 }
18 const unit = 1000 ** suffixNum;
19 const step = Math.abs(value) < 10 * unit ? unit / 10 : unit;
20 return `${(Math.trunc(value / step) * step) / unit}${suffixes[suffixNum]}`;
21}
22
23export const getRandom4Digits = (leftPad?: string): string => {
24 const random = Math.floor(1000 + Math.random() * 9000);

Callers 15

pluralizeFunction · 0.90
pluralFunction · 0.90
formatCountFunction · 0.90
packFollowersFunction · 0.90
claimedLabelFunction · 0.90
rankOfFunction · 0.90
headlineOfFunction · 0.90
UserBoardTileFunction · 0.90
CommentWithAwardFunction · 0.90
ProfileAwardsFunction · 0.90
BalanceFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected