Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#BigDecimal' - 4 code snippet(s) found

 Sample 1. Round a Big Decimal Number with 5 precision and to upper value using MathContext

MathContext mathContext = new MathContext(5,RoundingMode.HALF_UP);
       System.out.println(new BigDecimal(100.4767,mathContext));

   Like      Feedback     rounding a number  BigDecimal  rounding Bigdecimal  RoundingMode  MathContext  RoundingMode.HALF_UP


 Sample 2. Round a Big Decimal Number with 5 precision and to half lower value using MathContext

MathContext mathContext = new MathContext(5,RoundingMode.HALF_DOWN);
System.out.println(new BigDecimal(100.4767,mathContext));

   Like      Feedback     rounding a number  BigDecimal  rounding Bigdecimal  RoundingMode  MathContext  RoundingMode.HALF_DOWN


 Sample 3. Code Sample / Example / Snippet of java.math.BigDecimal

              public Void apply(ResultSet a0) {

try {

final BigDecimal bigDecimal = a0.getBigDecimal(1);

fail("expected error, got " + bigDecimal);

} catch (SQLException e) {

throw new RuntimeException(e);

} catch (NoSuchElementException e) {

}

try {

assertTrue(a0.next());

final BigDecimal bigDecimal = a0.getBigDecimal(1);

assertThat(bigDecimal, equalTo(BigDecimal.valueOf(2008)));

} catch (SQLException e) {

throw new RuntimeException(e);

}

return null;

}


   Like      Feedback      java.math.BigDecimal


 Sample 4. BigDecimal multiple method implementation

public BigDecimal multiply(BigDecimal multiplicand) {
int productScale = checkScale((long) scale + multiplicand.scale);
if (this.intCompact != INFLATED) {
if ((multiplicand.intCompact != INFLATED)) {
return multiply(this.intCompact, multiplicand.intCompact, productScale);
} else {
return multiply(this.intCompact, multiplicand.intVal, productScale);
}
} else {
if ((multiplicand.intCompact != INFLATED)) {
return multiply(multiplicand.intCompact, this.intVal, productScale);
} else {
return multiply(this.intVal, multiplicand.intVal, productScale);
}
}
}

   Like      Feedback     BigDecimal



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner