/** * Returns a rounded off number. If the value class is not Double, the value * is returned unchanged. * * @param value the value to return and potentially round off. */ public static Object getRoundedObject( Object value ) { return value != null && Double.class.equals( value.getClass() ) ? getRounded( (Double) value ) : value; }
/** * Rounds a value. If the given parameters has skip rounding, the value is * returned unchanged. If the given number is null or not of class Double, * the value is returned unchanged. If skip rounding is specified in the * given data query parameters, 10 decimals is used. Otherwise, default * rounding is used. * * @param params the query parameters. * @param value the value. * @return a value. */ public static Object getRoundedValueObject( DataQueryParams params, Object value ) { if ( value == null || !Double.class.equals( value.getClass() ) ) { return value; } else if ( params.isSkipRounding() ) { return Precision.round( (Double) value, DECIMALS_NO_ROUNDING ); } return MathUtils.getRounded( (Double) value ); }
/** * Fill grid with aggregated data map with key and value * * @param params the {@link DataQueryParams}. * @param grid the grid * @param aggregatedDataMap the aggregated data map */ private void fillGridWithAggregatedDataMap( DataQueryParams params, Grid grid, Map<String, Double> aggregatedDataMap) { for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() ) { Double value = params.isSkipRounding() ? entry.getValue() : MathUtils.getRounded( entry.getValue() ); grid.addRow() .addValues( entry.getKey().split( DIMENSION_SEP ) ) .addValue( value ); if ( params.isIncludeNumDen() ) { grid.addNullValues( 3 ); } } }
return MathUtils.getRounded( value );
private void getEvents( EventQueryParams params, Grid grid, String sql ) { log.debug( String.format( "Analytics event query SQL: %s", sql ) ); SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); while ( rowSet.next() ) { grid.addRow(); int index = 1; for ( GridHeader header : grid.getHeaders() ) { if ( ITEM_LONGITUDE.equals( header.getName() ) || ITEM_LATITUDE.equals( header.getName() ) ) { double val = rowSet.getDouble( index ); grid.addValue( Precision.round( val, COORD_DEC ) ); } else if ( Double.class.getName().equals( header.getType() ) && !header.hasLegendSet() ) { double val = rowSet.getDouble( index ); grid.addValue( params.isSkipRounding() ? val : MathUtils.getRounded( val ) ); } else { grid.addValue( rowSet.getString( index ) ); } index++; } } }
.addValue( params.isSkipRounding() ? value : MathUtils.getRounded( value ) );
grid.addValue( params.isSkipRounding() ? value : getRounded( value ) );