function formatNumberStandard()

in src/formattingService/formattingService.ts [625:695]


    function formatNumberStandard(value: number, format: string, culture: Culture): string {
        let result: string;
        let precision = <number>(format.length > 1 ? parseInt(format.substr(1, format.length - 1), 10) : undefined);
        let numberFormatInfo = culture.numberFormat;
        let formatChar = format.charAt(0);
        switch (formatChar) {
            case "e":
            case "E":
                if (precision === undefined) {
                    precision = 6;
                }
                let mantissaDecimalDigits = stringExtensions.repeat("0", precision);
                format = "0." + mantissaDecimalDigits + formatChar + "+000";
                result = formatNumberCustom(value, format, culture);
                break;
            case "f":
            case "F":
                result = precision !== undefined ? value.toFixed(precision) : value.toFixed(numberFormatInfo.decimals);
                result = localize(result, numberFormatInfo);
                break;
            case "g":
            case "G":
                let abs = Math.abs(value);
                if (abs === 0 || (1E-4 <= abs && abs < 1E15)) {
                    // For the range of 0.0001 to 1,000,000,000,000,000 - use the normal form
                    result = precision !== undefined ? value.toPrecision(precision) : value.toString();
                } else {
                    // Otherwise use exponential
                    // Assert that value is a number and fall back on returning value if it is not
                    if (typeof (value) !== "number")
                        return String(value);
                    result = precision !== undefined ? value.toExponential(precision) : value.toExponential();
                    result = result.replace("e", "E");
                }
                result = localize(result, numberFormatInfo);
                break;
            case "r":
            case "R":
                result = value.toString();
                result = localize(result, numberFormatInfo);
                break;
            case "x":
            case "X":
                result = value.toString(16);
                if (formatChar === "X") {
                    result = result.toUpperCase();
                }
                if (precision !== undefined) {
                    let actualPrecision = result.length;
                    let isNegative = value < 0;
                    if (isNegative) {
                        actualPrecision--;
                    }
                    let paddingZerosCount = precision - actualPrecision;
                    let paddingZeros = undefined;
                    if (paddingZerosCount > 0) {
                        paddingZeros = stringExtensions.repeat("0", paddingZerosCount);
                    }
                    if (isNegative) {
                        result = "-" + paddingZeros + result.substr(1);
                    } else {
                        result = paddingZeros + result;
                    }
                }
                result = localize(result, numberFormatInfo);
                break;
            default:
                result = Globalize.format(value, format, culture);
        }
        return result;
    }