Alex Rivera | Logout

Format Number like Stack Overflow (rounded to thousands with K suffix)

Asked 2010-01-25T17:25:29.107
41

How to format numbers like SO with C#?

10, 500, 5k, 42k, ...

Edit
Report

1 Answer

0

Something like this:

string formatted;
if (num >= 1000) {
    formatted = ((double)num / 1000.0).ToString("N1") + "k";
} else {
    formatted = num.ToString("N0");
}
answered 2010-01-25T17:29:27.493

Your Answer