2

Is there a generic/better way to shorten larger numbers?
Numbers > 1000 should to shortened to two decimal places and appended a 'k' e.g. 1543 should become 1.54k, while 1504 should be shortened to 1.5k and 1007 shortened to 1k.

The same should be done for numbers > 1000000, they should get M appended.
Example: 5426849 should be shortened to 5.42M (wouldn't mind 5.43M), 5403258 shortened to 5.4M and 5001485 shortened to 5M.

Currently I have this:

std::string letter(_sum > 1000000 ? "M" : _sum > 1000 ? "k" : "");
float displayValue(_sum > 1000000 ? _sum/1000000 : _sum > 1000 ? _sum/1000 : _sum);
printf("%.2g%s", displayValue, letter);
xNidhogg
  • 331
  • 1
  • 4
  • 12

0 Answers0