Ejemplo n.º 1
0
            private static string FormatFixed(BigDouble value, int places)
            {
                if (places < 0)
                {
                    places = MaxSignificantDigits;
                }
                if (value.Exponent <= -ExpLimit || IsZero(value.Mantissa))
                {
                    return("0" + (places > 0 ? ".".PadRight(places + 1, '0') : ""));
                }

                // two cases:
                // 1) exponent is 17 or greater: just print out mantissa with the appropriate number of zeroes after it
                // 2) exponent is 16 or less: use basic toFixed

                if (value.Exponent >= MaxSignificantDigits)
                {
                    // TODO: StringBuilder-optimizable
                    return(value.Mantissa
                           .ToString(CultureInfo.InvariantCulture)
                           .Replace(".", "")
                           .PadRight((int)value.Exponent + 1, '0')
                           + (places > 0 ? ".".PadRight(places + 1, '0') : ""));
                }
                return(ToFixed(value.ToDouble(), places));
            }
Ejemplo n.º 2
0
            private static string FormatGeneral(BigDouble value, int places)
            {
                if (value.Exponent <= -ExpLimit || IsZero(value.Mantissa))
                {
                    return("0");
                }

                var format = places > 0 ? $"G{places}" : "G";

                if (value.Exponent < 21 && value.Exponent > -7)
                {
                    return(value.ToDouble().ToString(format, new CultureInfo("en-US")));
                }

                return(value.Mantissa.ToString("F2")
                       + "e" + value.Exponent.ToString(new CultureInfo("en-US")));
            }
Ejemplo n.º 3
0
            private static string FormatGeneral(BigDouble value, int places)
            {
                if (value.Exponent <= -ExpLimit || IsZero(value.Mantissa))
                {
                    return("0");
                }

                var format = places > 0 ? $"G{places}" : "G";

                if (value.Exponent < 21 && value.Exponent > -7)
                {
                    return(value.ToDouble().ToString(format, CultureInfo.InvariantCulture));
                }

                return(value.Mantissa.ToString(format, CultureInfo.InvariantCulture)
                       + "E" + (value.Exponent >= 0 ? "+" : "")
                       + value.Exponent.ToString(CultureInfo.InvariantCulture));
            }