Are you looking for customized advices? Click here to contact the expert!
by
3
6
369k
3
Top 1% !
Popular
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 2434th place
Created
Modified Oct 14, 2014

Published on:

.NETFramework1.0
Extension.cs
LanguageCSharp
LicenseMIT_X11
OSWindows

How to prettify a number with thousands or millions

Prepares a pretty version of the given number, with the ability to match the right plural/singular form for English text
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/195986/How-to-prettify-a-number-with-thousands-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static string PaintNumber(int number, string followingText = "", bool numberInBold = false) { string content = String.Format("{0:N0}", number); if (number >= 10000) { double numberInThousands = number / 1000.0; if (numberInThousands < 100) content = String.Format("{0:N0}k", numberInThousands); else content = String.Format("{0:0.#}M", numberInThousands / 1000.0); } if (number >= 1000000) { double numberInMillions = number / 1000000.0; if (numberInMillions < 100) content = String.Format("{0:N0}M", numberInMillions); else content = String.Format("{0:0.#}B", numberInMillions / 1000.0); } if (numberInBold) content = "<b>" + content + "</b>"; if (!string.IsNullOrEmpty(followingText)) content += " " + followingText + (number != 1 ? "s" : ""); return content; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus