using System.Collections;
using System.Collections.Generic;
using System.Globalization;
public static void Main()
PrintNumber(Math.Pow(10.00001,4));
PrintNumber(Math.Pow(10.00001,20));
PrintNumber(Math.Pow(10.00001,21));
PrintNumber(Math.Pow(10.00001,50));
private static void PrintNumber(double number){
Console.WriteLine($"Global: {number.Format()} = {number.FormatChinese()}: Chinese");
public static class NumberTools{
public static string Format(this double value, bool decimals = false) {
return FormattedText (value, ShortScales, decimals);
public static string FormatChinese(this double value, bool decimals = false) {
return FormattedText (value, ShortScalesChinese, decimals, 4);
private static string FormattedText(double value, List<string> scales, bool decimals = false, int scalePower = 3)
if (decimals && value < Math.Pow(10, scalePower))
for (; digits < scalePower; digits++)
if (value < Math.Pow(10, digits))
return value.ToString($"F{scalePower - digits}", CultureInfo.InvariantCulture);
else if (value >= Math.Pow(10, scalePower))
var digits = value.CountDigits();
var text = value.ToString("F0").Substring(0, scalePower);
var left = digits % scalePower;
if (left != 0) text = text.Insert(left, ".");
var scale = digits - left;
return text + scales[scale / scalePower - 1];
return value.ToString("F0");
private static int CountDigits(this double value)
return value >= 1 ? (int) System.Math.Floor(System.Math.Log10(value) + 1) : 0;
private static readonly List<string> ShortScales = new List<string> (new string[] {
private static readonly List<string> ShortScalesChinese = new List<string> (new string[] {