← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5137: Data entry, rounding to one decimal if not zero for indicator values in custom forms

 

------------------------------------------------------------
revno: 5137
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-11-10 21:03:03 +0100
message:
  Data entry, rounding to one decimal if not zero for indicator values in custom forms
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-11-09 11:06:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-11-10 20:03:03 +0000
@@ -1481,4 +1481,19 @@
 function getRandomNumber()
 {
 	return Math.floor( 1000000 * Math.random() );
-}
\ No newline at end of file
+}
+
+/**
+ * Rounds the given number to the given number of decimals.
+ */
+function roundTo( number, decimals )
+{
+	if ( number == null || isNaN( number ) || decimals == null || isNaN( decimals ) )
+	{
+		return number;
+	}
+	
+	var factor = Math.pow( 10, decimals );
+		
+	return ( Math.round( number * factor ) / factor );
+}

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-11-09 18:18:11 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-11-10 20:03:03 +0000
@@ -36,7 +36,7 @@
         {
 	        var value = eval( expression );
 	        
-	        value = isNaN( value ) ? '-' : Math.round( value );
+	        value = isNaN( value ) ? '-' : roundTo( value, 1 );
 	
 	        $( this ).attr( 'value', value );
         }