MCPcopy
hub / github.com/ing-bank/lion / formatNumber

Function formatNumber

packages/ui/components/localize/src/number/formatNumber.js:16–54  ·  view source on GitHub ↗
(number, options = /** @type {FormatOptions} */ ({}))

Source from the content-addressed store, hash-verified

14 * @returns {string}
15 */
16export function formatNumber(number, options = /** @type {FormatOptions} */ ({})) {
17 const localizeManager = getLocalizeManager();
18 if (number === undefined || number === null) return '';
19 const formattedToParts = formatNumberToParts(number, options);
20 // If number is not a number
21 if (
22 formattedToParts === options.returnIfNaN ||
23 formattedToParts === localizeManager.formatNumberOptions.returnIfNaN
24 ) {
25 return /** @type {string} */ (formattedToParts);
26 }
27 let printNumberOfParts = '';
28 // update numberOfParts because there may be some parts added
29 const numberOfParts = formattedToParts ? formattedToParts.length : 0;
30 for (let i = 0; i < numberOfParts; i += 1) {
31 const part = /** @type {FormatNumberPart} */ (formattedToParts[i]);
32 printNumberOfParts += part.value;
33 }
34
35 const computedLocale = getLocale(options && options.locale);
36
37 if (localizeManager.formatNumberOptions.postProcessors.size > 0) {
38 Array.from(localizeManager.formatNumberOptions.postProcessors).forEach(([locale, fn]) => {
39 if (locale === computedLocale) {
40 printNumberOfParts = fn(printNumberOfParts);
41 }
42 });
43 }
44
45 if (options.postProcessors && options.postProcessors.size > 0) {
46 Array.from(options.postProcessors).forEach(([locale, fn]) => {
47 if (locale === computedLocale) {
48 printNumberOfParts = fn(printNumberOfParts);
49 }
50 });
51 }
52
53 return printNumberOfParts;
54}

Callers 8

fnFunction · 0.90
fn2Function · 0.90
fn3Function · 0.90
fn4Function · 0.90
_inputGroupTemplateMethod · 0.90
formatAmountFunction · 0.90

Calls 4

getLocalizeManagerFunction · 0.90
formatNumberToPartsFunction · 0.90
getLocaleFunction · 0.90
fnFunction · 0.85

Tested by 4

fnFunction · 0.72
fn2Function · 0.72
fn3Function · 0.72
fn4Function · 0.72