Java Code Examples for java.math.RoundingMode#CEILING
The following examples show how to use
java.math.RoundingMode#CEILING .
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: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * new BigDecimal(char[] value, int offset, int len, MathContext mc); */ public void testConstrCharIntIntMathContext() { char value[] = {'-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3'}; int offset = 3; int len = 12; int precision = 4; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); BigDecimal result = new BigDecimal(value, offset, len, mc); String res = "3.805E-40"; int resScale = 43; assertEquals("incorrect value", res, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); try { // Regression for HARMONY-783 new BigDecimal(new char[] {}, 0, 0, MathContext.DECIMAL32); fail("NumberFormatException has not been thrown"); } catch (NumberFormatException e) { } }
Example 2
Source File: IntegerMultiplyOperationCalculatorTest.java From jtwig-core with Apache License 2.0 | 6 votes |
@Test public void calculate() throws Exception { RoundingMode roundingMode = RoundingMode.CEILING; RenderRequest request = mock(RenderRequest.class, RETURNS_DEEP_STUBS); BigDecimal left = mock(BigDecimal.class); BigDecimal right = mock(BigDecimal.class); BigDecimal leftRounded = mock(BigDecimal.class); BigDecimal rightRounded = mock(BigDecimal.class); BigDecimal expected = mock(BigDecimal.class); when(request.getEnvironment().getValueEnvironment().getRoundingMode()).thenReturn(roundingMode); when(left.setScale(0, roundingMode)).thenReturn(leftRounded); when(right.setScale(0, roundingMode)).thenReturn(rightRounded); when(leftRounded.multiply(rightRounded)).thenReturn(expected); BigDecimal result = underTest.calculate(request, left, right); assertEquals(expected, result); }
Example 3
Source File: IntegerDivideOperationCalculatorTest.java From jtwig-core with Apache License 2.0 | 6 votes |
@Test public void calculate() throws Exception { MathContext mathContext = MathContext.DECIMAL128; RoundingMode roundingMode = RoundingMode.CEILING; RenderRequest request = mock(RenderRequest.class, RETURNS_DEEP_STUBS); BigDecimal left = mock(BigDecimal.class); BigDecimal right = mock(BigDecimal.class); BigDecimal leftRounded = mock(BigDecimal.class); BigDecimal rightRounded = mock(BigDecimal.class); BigDecimal divisionResult = mock(BigDecimal.class); BigDecimal expected = mock(BigDecimal.class); when(request.getEnvironment().getValueEnvironment().getMathContext()).thenReturn(mathContext); when(request.getEnvironment().getValueEnvironment().getRoundingMode()).thenReturn(roundingMode); when(left.setScale(0, roundingMode)).thenReturn(leftRounded); when(right.setScale(0, roundingMode)).thenReturn(rightRounded); when(leftRounded.divide(rightRounded, mathContext)).thenReturn(divisionResult); when(divisionResult.setScale(0, roundingMode)).thenReturn(expected); BigDecimal result = underTest.calculate(request, left, right); assertEquals(expected, result); }
Example 4
Source File: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * new BigDecimal(String value, MathContext) */ public void testConstrStringMathContext() { String a = "-238768787678287e214"; int precision = 5; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String res = "-23876"; int resScale = -224; BigDecimal result = new BigDecimal(a, mc); assertEquals("incorrect value", res, result.unscaledValue().toString()); assertEquals("incorrect scale", resScale, result.scale()); }
Example 5
Source File: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * new BigDecimal(BigInteger value, int scale, MathContext) */ public void testConstrBigIntegerScaleMathContext() { String a = "1231212478987482988429808779810457634781384756794987"; BigInteger bA = new BigInteger(a); int aScale = 10; int precision = 46; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String res = "1231212478987482988429808779810457634781384757"; int resScale = 4; BigDecimal result = new BigDecimal(bA, aScale, mc); assertEquals("incorrect value", res, result.unscaledValue().toString()); assertEquals("incorrect scale", resScale, result.scale()); }
Example 6
Source File: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * new BigDecimal(BigInteger value, MathContext) */ public void testConstrBigIntegerMathContext() { String a = "1231212478987482988429808779810457634781384756794987"; BigInteger bA = new BigInteger(a); int precision = 46; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String res = "1231212478987482988429808779810457634781384757"; int resScale = -6; BigDecimal result = new BigDecimal(bA, mc); assertEquals("incorrect value", res, result.unscaledValue().toString()); assertEquals("incorrect scale", resScale, result.scale()); }
Example 7
Source File: BigDecimalCompareTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * negate(MathContext) for a negative BigDecimal */ public void testNegateMathContextNegative() { String a = "-92948782094488478231212478987482988429808779810457634781384756794987"; int aScale = 49; int precision = 46; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String c = "9294878209448847823.121247898748298842980877982"; int cScale = 27; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal res = aNumber.negate(mc); assertEquals("incorrect value", c, res.toString()); assertEquals("incorrect scale", cScale, res.scale()); }
Example 8
Source File: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * new BigDecimal(long, MathContext) */ public void testConstrLongMathContext() { long a = 4576578677732546982L; int precision = 5; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String res = "45766"; int resScale = -14; BigDecimal result = new BigDecimal(a, mc); assertEquals("incorrect value", res, result.unscaledValue().toString()); assertEquals("incorrect scale", resScale, result.scale()); }
Example 9
Source File: BigDecimalConstructorsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * new BigDecimal(int, MathContext) */ public void testConstrIntMathContext() { int a = 732546982; int precision = 21; RoundingMode rm = RoundingMode.CEILING; MathContext mc = new MathContext(precision, rm); String res = "732546982"; int resScale = 0; BigDecimal result = new BigDecimal(a, mc); assertEquals("incorrect value", res, result.unscaledValue().toString()); assertEquals("incorrect scale", resScale, result.scale()); }
Example 10
Source File: BigDecimalArithmeticTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * divide(BigDecimal, scale, RoundingMode) */ public void testDivideBigDecimalScaleRoundingModeCEILING() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 100; String b = "74723342238476237823787879183470"; int bScale = 15; int newScale = 45; RoundingMode rm = RoundingMode.CEILING; String c = "1E-45"; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divide(bNumber, newScale, rm); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", newScale, result.scale()); }
Example 11
Source File: PrecisionContextRoundedOperatorTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = NullPointerException.class) public void shouldReturnErrorWhenParameterIsNull() { MathContext mathContext = new MathContext(2, RoundingMode.CEILING); PrecisionContextRoundedOperator monetaryOperator = PrecisionContextRoundedOperator.of(mathContext); monetaryOperator.apply(null); fail(); }
Example 12
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 13
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 14
Source File: RoundingModeTests.java From openjdk-jdk9 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: 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 16
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 17
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 18
Source File: CeilDecimalExpression.java From phoenix with Apache License 2.0 | 4 votes |
@Override protected RoundingMode getRoundingMode() { return RoundingMode.CEILING; }
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"); } }