This might be a bit of an overkill solution but should be quite configurable. Just add/merge this code into your qa-theme.php file:
private $suffixes = array('', 'k', 'm');
private function formatViews($size, $precision = 1) {
$base = log($size) / log(1000);
return round(pow(1000, $base - floor($base)), $precision) . $this->suffixes[floor($base)];
}
private function updateViewCount(&$questionItem) {
if (isset($questionItem['views_raw'], $questionItem['views']['data'])) {
$questionItem['views']['data'] = $this->formatViews($questionItem['views_raw']);
}
}
public function q_view($q_item) {
$this->updateViewCount($q_item);
qa_html_theme_base::q_view($q_item);
}
public function q_list_item($q_item) {
$this->updateViewCount($q_item);
qa_html_theme_base::q_list_item($q_item);
}
Some notes:
-
This should work for question lists and question view pages
-
You can change the precision (amount of digits after the decimal separator) with $precision = X
-
If you already had any of the q_list_item or q_view functions already defined then just add $this->updateViewCount($q_item); as the first line inside them and do not add those functions twice
-
You can change the suffixes in the array on top. Currently 'k' for 1000 and 'm' for 1000000. If you need more you can add... but I hardly believe you would :)
-
Example for a precision of 1: 123,456 turns into 123.5k