MCPcopy Create free account
hub / github.com/apitable/apitable / numberToShow

Function numberToShow

packages/core/src/utils/number.ts:141–165  ·  view source on GitHub ↗
(value: number, precision = 0)

Source from the content-addressed store, hash-verified

139 * @param demarcationLen Several digits show the demarcation point for scientific notation
140 */
141export function numberToShow(value: number, precision = 0): string | null {
142 value = Number(value);
143 if (isNaN(value)) {
144 return 'NaN';
145 }
146
147 if (value === Infinity) {
148 return 'Infinity';
149 }
150
151 let str = value.toString();
152
153 const integerCount = str.split('.')[0]!.length;
154 const demarcationLen = 17; // 17 digits represent the demarcation point for scientific notation
155 // When the integer number is greater than 17, it needs to be displayed in scientific notation form
156 if (integerCount >= demarcationLen || (str.includes('e') && !str.includes('e-'))) {
157 const significanceDigitCount = 5; // number of significant digits after the decimal point
158 // There will also be precision problems, but because there are already precision requirements in the premise, there will be no rounding problems
159 str = value.toExponential(significanceDigitCount);
160 } else {
161 str = toFixed(value, precision);
162 }
163
164 return str;
165}
166const CapacityUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
167// decimal point by 1
168// For example, 1.23 and 1.26 both return 1.3

Callers 6

cellValueToStringMethod · 0.90
cellValueToStringMethod · 0.90
numberFormatFunction · 0.90
cellValueToStringMethod · 0.90
setEditorValueFunction · 0.90

Calls 2

toFixedFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected