← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9790: (PT) Rounding totals to one decimal.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 9790 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-02-12 14:11:14 +0100
message:
  (PT) Rounding totals to one decimal.
modified:
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-02-12 12:39:34 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-02-12 13:09:58 +0000
@@ -423,6 +423,18 @@
 		}
 	};
 
+	util.number = {
+		getNumberOfDecimals: function(x) {
+			var tmp = new String(x);
+			return (tmp.indexOf(".") > -1) ? (tmp.length - tmp.indexOf(".") - 1) : 0;
+		},
+
+		roundIf: function(x, fix) {
+			var dec = pt.util.number.getNumberOfDecimals(x);
+			return parseFloat(dec > fix ? x.toFixed(fix) : x);
+		}
+	};
+
 	util.pivot = {
 		getTable: function(settings, pt, container) {
 			var getParamStringFromDimensions,
@@ -1006,7 +1018,8 @@
 
 						// Total row html items
 						for (var i = 0, rowSum; i < totalRowItems.length; i++) {
-							rowSum = totalRowItems[i];
+							rowSum = totalRowItems[i];							
+							rowSum = pt.util.number.roundIf(rowSum, 1);
 
 							a.push(['<td id="nissa" class="pivot-valuetotal">' + rowSum.toString() + '</td>']);
 						}
@@ -1028,13 +1041,14 @@
 							for (var j = 0; j < valueItems.length; j++) {
 								colSum += valueItems[j][i];
 							}
-
+							
 							totalColItems.push(colSum);
 						}
 
 						// Total col html items
 						for (var i = 0, colSum; i < totalColItems.length; i++) {
 							colSum = totalColItems[i];
+							colSum = pt.util.number.roundIf(colSum, 1);
 
 							a.push('<td class="pivot-valuetotal">' + colSum.toString() + '</td>');
 						}
@@ -1044,13 +1058,14 @@
 				};
 
 				getGrandTotalHtmlArray = function() {
-					var grandTotalItem,
+					var grandTotalSum,
 						a = [];
 
 					if (xColAxis && xRowAxis) {
-						grandTotalItem = Ext.Array.sum(totalColItems) || 0;
+						grandTotalSum = Ext.Array.sum(totalColItems) || 0;
+						grandTotalSum = pt.util.number.roundIf(grandTotalSum, 1);
 
-						a.push('<td class="pivot-valuegrandtotal">' + grandTotalItem.toString() + '</td>');
+						a.push('<td class="pivot-valuegrandtotal">' + grandTotalSum.toString() + '</td>');
 					}
 
 					return a;