Created
March 11, 2020 09:59
-
-
Save oivoodoo/ad9f4ddf99610993ab6354e0096ab8a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Globalization; | |
public static class FormatNumber | |
{ | |
public static string ToKMB(this decimal num) | |
{ | |
if (num > 999999999 || num < -999999999) | |
{ | |
return num.ToString("0,,,.###B", CultureInfo.InvariantCulture); | |
} | |
if (num > 999999 || num < -999999) | |
{ | |
return num.ToString("0,,.##M", CultureInfo.InvariantCulture); | |
} | |
if (num > 999 || num < -999) | |
{ | |
return num.ToString("0,.#K", CultureInfo.InvariantCulture); | |
} | |
return num.ToString(CultureInfo.InvariantCulture); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment