Project:Views Calc
Version:6.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Perhaps I'm missing something, but it seems we need a way to define how many decimals places to show when averaging something out. Right now I'm averaging something and it's giving me 0.222222222222222. This is obnoxious and takes up a lot of room.

Isn't there a way to limit it to two decimal places?

Comments

#1

Am I the only one having this issue? If it's something I'm overlooking I'd appreciate someone telling me so :P Driving me crazy for weeks now.

#2

Bump.

Anybody?

#3

Is anyone else even having this issue? What am I doing wrong? I've been looking for months now...

#4

Yea, for my averages I am getting 4 decimal places (e.g 1.5321)

#5

Copy the view-calc-table.tpl.php file (found in the views_calc module folder) to your theme folder. Clear your cache (by going to admin/settings/performance and hitting the "clear cache" button). Your theme will now recognize this new template file.

You can now use the round() function to round the results down using the following code:

<td class="view-footer views-field views-field-<?php print $fields[$field]; ?>  <?php print $options['info'][$field]['justification'] ?>">
  <?php print round($content, 2); ?>
</td>

This will round all of the calculations to the nearest 100th (1.00). Lookup the round() php function on google to learn more about how to use it, its pretty easy (e.g. round($content, 0) will round 1.5432 to 2).

#6

Status:active» closed (fixed)

You are AMAZING. Thank you :)

#7

You will probably be better with something like:

                <?php   
               
if (is_numeric($content)) print number_format($content,1,'.',',');
                else  print
$content; ?>

So that labels don't disappear, spaces are not transformed to zeros, and if you use number_format you can even specify thousands and decimal separators.