c# - Format Number like (rounded to thousands with K suffix)
How to format numbers such as SO with C?
10, 5k, ...
like this: ( Edit : test)
Fixed string format number (integer number) {if (digits> gt = = 100000) return format (number / 1000) + "k"; If (numerals> = 10000) {return (digits / 1000d). Toastring ("0. #") + "K"; } Return num.ToString ("#, 0"); }
Example:
- 1 =>
1
- 23 =>
23 < / Code>
- 136 =>
136
- 6968 =>
6,968
- 23067 => < Code> 23.1K
- 133031 =>
133K
Note that this will give strange values to numbers> = 10 < Sup> 8 . For example, 12345678
becomes 12.3KK
.
Comments
Post a Comment