Package java.math

Examples of java.math.RoundingMode


        '-', '1', '2', '3', '8', '0', ',', '4', '7', '3', '8', 'E', '-', '4',
        '2', '3'};
    int offset = 3;
    int len = 120;
    int precision = 4;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    try {
      new BigDecimal(value, offset, len, mc);
      fail("NumberFormatException has not been thrown");
    } catch (NumberFormatException e) {
View Full Code Here


  public void testConstrCharMathContext() {
    char value[] = {
        '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2'
    };
    int precision = 4;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    BigDecimal result = new BigDecimal(value, mc);
    String res = "3.805E-40";
    int resScale = 43;
    assertEquals("incorrect value", res, result.toString());
View Full Code Here

   * new BigDecimal(double, MathContext).
   */
  public void testConstrDoubleMathContext() {
    double a = 732546982374982347892379283571094797.287346782359284756;
    int precision = 21;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    BigDecimal result = new BigDecimal(a, mc);
    BigDecimal expected = new BigDecimal("732546982374982e21");
    assertEquals(expected, result, 1e21);
    try {
View Full Code Here

   * 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());
View Full Code Here

   * 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());
View Full Code Here

   * 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());
View Full Code Here

    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = 45;
    String b = "134432345432345748766876876723342238476237823787879183470";
    int bScale = 20;
    int precision = 15;
    RoundingMode rm = RoundingMode.DOWN;
    MathContext mc = new MathContext(precision, rm);
    String res = "0E-25";
    int resScale = 25;
    String rem = "3736186567876.876578956958765675671119238118911893939591735";
    int remScale = 45;
View Full Code Here

    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = 45;
    String b = "134432345432345748766876876723342238476237823787879183470";
    int bScale = 70;
    int precision = 75;
    RoundingMode rm = RoundingMode.UP;
    MathContext mc = new MathContext(precision, rm);
    String res = "277923185514690367474770683";
    int resScale = 0;
    String rem = "1.3032693871288309587558885943391070087960319452465789990E-15";
    int remScale = 70;
View Full Code Here

    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = 15;
    String b = "748766876876723342238476237823787879183470";
    int bScale = 70;
    int precision = 21;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    String c = "4.98978611802562512996E+70";
    int resScale = -50;
    BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
View Full Code Here

    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = 15;
    String b = "748766876876723342238476237823787879183470";
    int bScale = 70;
    int precision = 21;
    RoundingMode rm = RoundingMode.DOWN;
    MathContext mc = new MathContext(precision, rm);
    String c = "4.98978611802562512995E+70";
    int resScale = -50;
    BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
View Full Code Here

TOP

Related Classes of java.math.RoundingMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.