Java Code Examples for java.math.RoundingMode#valueOf()
The following examples show how to use
java.math.RoundingMode#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoubleRoundTo.java From spork with Apache License 2.0 | 6 votes |
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Double exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Double num = (Double)input.get(0); Integer digits = (Integer)input.get(1); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.doubleValue(); } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
Example 2
Source File: ROUND_TO.java From spork with Apache License 2.0 | 6 votes |
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Double exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Double num = DataType.toDouble(input.get(0)); Integer digits = DataType.toInteger(input.get(1)); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.doubleValue(); } catch (NumberFormatException nfe){ System.err.println("Failed to process input; error - " + nfe.getMessage()); return null; } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
Example 3
Source File: FloatRoundTo.java From spork with Apache License 2.0 | 6 votes |
/** * java level API * @param input expects a numeric value to round, a number of digits to keep, and an optional rounding mode. * @return output returns a single numeric value, the number with only those digits retained */ @Override public Float exec(Tuple input) throws IOException { if (input == null || input.size() < 2) return null; try { Float num = (Float)input.get(0); Integer digits = (Integer)input.get(1); RoundingMode mode = (input.size() >= 3) ? RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN; if (num == null) return null; BigDecimal bdnum = BigDecimal.valueOf(num); bdnum = bdnum.setScale(digits, mode); return bdnum.floatValue(); } catch (Exception e){ throw new IOException("Caught exception processing input row ", e); } }
Example 4
Source File: ValueDataUtil.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private static MathContext buildMathContext( VariableSpace space ) { String precisionString = space.getVariable( Const.KETTLE_BIGDECIMAL_DIVISION_PRECISION ); String roundingModeString = space.getVariable( Const.KETTLE_BIGDECIMAL_DIVISION_ROUNDING_MODE ); if ( precisionString != null ) { RoundingMode roundingMode; try { roundingMode = RoundingMode.valueOf( roundingModeString ); } catch ( IllegalArgumentException | NullPointerException e ) { roundingMode = RoundingMode.HALF_EVEN; } int precision = Integer.parseInt( precisionString ); if ( precision < 0 ) { return MathContext.UNLIMITED; } else { return new MathContext( precision, roundingMode ); } } return MathContext.UNLIMITED; }
Example 5
Source File: DefaultBigDecimalMath.java From big-math with MIT License | 5 votes |
private static RoundingMode getRoundingModeSystemProperty(String propertyKey, RoundingMode defaultValue) { String propertyValue = System.getProperty(propertyKey, defaultValue.name()); try { return RoundingMode.valueOf(propertyValue); } catch(IllegalArgumentException ex) { return propertyException(propertyKey,propertyValue,defaultValue); } }
Example 6
Source File: DefaultMonetaryContextFactory.java From jsr354-ri with Apache License 2.0 | 5 votes |
private MonetaryContext createMonetaryContextNonNullConfig(Map<String, String> config, int prec) { String value = config.get("org.javamoney.moneta.Money.defaults.roundingMode"); RoundingMode rm = Objects.nonNull(value) ? RoundingMode.valueOf(value .toUpperCase(Locale.ENGLISH)) : RoundingMode.HALF_UP; MonetaryContext mc = MonetaryContextBuilder.of(Money.class).setPrecision(prec).set(rm).set(Money.class).build(); Logger.getLogger(DefaultMonetaryContextFactory.class.getName()).info("Using custom MathContext: precision=" + prec + ", roundingMode=" + rm); return mc; }
Example 7
Source File: TestResource.java From AVM with MIT License | 5 votes |
@Callable public static boolean testInvalidRoundingModeEnum() { try { RoundingMode.valueOf("up"); throw new AssertionError(); } catch (IllegalArgumentException e){ // Expected } return true; }
Example 8
Source File: RoundingModeTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 9
Source File: RoundingModeTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 10
Source File: RoundingModeTests.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 11
Source File: RoundingModeTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 12
Source File: RoundingModeTests.java From hottub with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 13
Source File: RoundingModeTests.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 14
Source File: RoundingModeTests.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 15
Source File: NumberFormatValue.java From birt with Eclipse Public License 1.0 | 4 votes |
public static NumberFormatValue getInstance( String numberFormat ) { if ( numberFormat != null ) { NumberFormatValue value = new NumberFormatValue( ); Matcher matcher = pattern.matcher( numberFormat ); if ( matcher.matches( ) ) { String f = matcher.group( 1 ); if ( f != null && f.length( ) > 0 ) { value.format = f; int index = f.lastIndexOf( '.' ); if ( index > 0 ) { int end = f.length( ); for ( int i = index + 1; i < f.length( ); i++ ) { if ( f.charAt( i ) != '0' ) { end = i; break; } } value.fractionDigits = end - 1 - index; } char lastChar = f.charAt( f.length( ) - 1 ); switch ( lastChar ) { case '%' : value.fractionDigits += 2; break; case '‰' : value.fractionDigits += 3; break; case '‱' : value.fractionDigits += 4; break; } } String m = matcher.group( 2 ); if ( m != null ) { value.roundingMode = RoundingMode.valueOf( m ); } } else { value.format = numberFormat; } return value; } return null; }
Example 16
Source File: RoundingModeTests.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 17
Source File: RoundingModeTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 18
Source File: RoundingModeTests.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 19
Source File: RoundingModeTests.java From native-obfuscator with GNU General Public License v3.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }
Example 20
Source File: RoundingModeTests.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String [] argv) { // For each member of the family, make sure // rm == valueOf(rm.toString()) for(RoundingMode rm: RoundingMode.values()) { if (rm != RoundingMode.valueOf(rm.toString())) { throw new RuntimeException("Bad roundtrip conversion of " + rm.toString()); } } // Test that mapping of old integers to new values is correct if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) != RoundingMode.CEILING) { throw new RuntimeException("Bad mapping for ROUND_CEILING"); } if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) != RoundingMode.DOWN) { throw new RuntimeException("Bad mapping for ROUND_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) != RoundingMode.FLOOR) { throw new RuntimeException("Bad mapping for ROUND_FLOOR"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) != RoundingMode.HALF_DOWN) { throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) != RoundingMode.HALF_EVEN) { throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN"); } if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) != RoundingMode.HALF_UP) { throw new RuntimeException("Bad mapping for ROUND_HALF_UP"); } if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) != RoundingMode.UNNECESSARY) { throw new RuntimeException("Bad mapping for ROUND_UNNECESARY"); } }