=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java 2014-11-03 00:24:32 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java 2014-11-03 02:28:32 +0000 @@ -50,6 +50,7 @@ { private static final DecimalFormat FORMAT_VALUE = new DecimalFormat( "#.#" ); // Fixed for now private static final String EMPTY = ""; + private static final String NAN = "NaN"; private static final String INVALID_DATE = "Invalid date format"; @@ -269,7 +270,8 @@ } /** * Formats value. Returns empty string if value is null. Returns NaN if value - * is not a number. + * is not a number. Return a formatted string if value is an instance of Number, + * if not returns the value as a string. * * @param value the value to format. */ @@ -280,11 +282,18 @@ return EMPTY; } - try + if ( value instanceof Number ) { - return FORMAT_VALUE.format( value ); + try + { + return FORMAT_VALUE.format( value ); + } + catch ( IllegalArgumentException ex ) + { + return NAN; + } } - catch ( IllegalArgumentException ex ) + else { return String.valueOf( value ); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2014-11-03 00:24:32 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2014-11-03 02:28:32 +0000 @@ -28,13 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.apache.commons.lang.StringUtils.trimToEmpty; import static org.hisp.dhis.dataentryform.DataEntryFormService.DATAELEMENT_TOTAL_PATTERN; import static org.hisp.dhis.dataentryform.DataEntryFormService.IDENTIFIER_PATTERN; import static org.hisp.dhis.dataentryform.DataEntryFormService.INDICATOR_PATTERN; import static org.hisp.dhis.dataentryform.DataEntryFormService.INPUT_PATTERN; import static org.hisp.dhis.datasetreport.DataSetReportStore.SEPARATOR; -import static org.hisp.dhis.system.util.MathUtils.getRoundedObject; import java.util.ArrayList; import java.util.Collections; @@ -323,7 +321,7 @@ Object dataValue = dataValues.get( dataElementId + SEPARATOR + optionComboId ); - String value = "" + trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) + ""; + String value = "" + format.formatValue( dataValue ) + ""; inputMatcher.appendReplacement( buffer, value ); } @@ -333,7 +331,7 @@ Object dataValue = dataValues.get( dataElementId ); - inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) ); + inputMatcher.appendReplacement( buffer, format.formatValue( dataValue ) ); } else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 ) { @@ -341,7 +339,7 @@ Object indicatorValue = indicatorValues.get( indicatorId ); - inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( indicatorValue ) ) ) ); + inputMatcher.appendReplacement( buffer, format.formatValue( indicatorValue ) ); } }