CSharp · Console
using System;
using Markdig;
public class Program
{
public static void Main()
{
Console.WriteLine(GetFormat(1)); //-> 1
Console.WriteLine(GetFormat(10)); //-> 10
Console.WriteLine(GetFormat(100)); //-> 100
Console.WriteLine(GetFormat(1000)); //-> 1K
Console.WriteLine(GetFormat(1100)); //-> 1,1K
Console.WriteLine(GetFormat(10000)); //-> 10K
Console.WriteLine(GetFormat(11000)); //-> 11K
Console.WriteLine(GetFormat(100000)); //-> 100K
Console.WriteLine(GetFormat(1000000)); //-> 1M
}
public static string GetFormat(int value)
{
if (value >= 1000000)
{
return (value / 1000000m) + "M";
}
else if (value >= 1000)
{
return (value / 1000m) + "K";
}
else
{
return value.ToString();
}
}
}