Java 8 BigDecimal - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BigDecimal class.

This code example shows how to use the following methods:
public class JdbcDecimalTest 
{ 
    @Test 
    public void testComposeDecompose() 
    { 
        BigDecimal expected = new BigDecimal("123456789123456789.987654321");
        DecimalSerializer decimal = new DecimalSerializer();
         
        ByteBuffer buffer = decimal.serialize(expected);
        BigDecimal actual = decimal.deserialize(buffer);
        Assert.assertEquals(expected, actual);
    } 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
 
        BigDecimal decimal;
 
        try 
        { 
            decimal = new BigDecimal(source);
        } 
        catch (Exception e)
        { 
            throw new MarshalException(String.format("unable to make BigDecimal from '%s'", source), e);
        } 
 
        return decompose(decimal);
    } 
 
    public CQL3Type asCQL3Type() 
    { 
        return CQL3Type.Native.DECIMAL; 
    } 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toString
     * when value is not a valid representation of BigDecimal. 
     */ 
    public void testConstrStringException() { 
        String a = "-238768.787678287a+10";
        try { 
            BigDecimal bd = new BigDecimal(a);
            fail("NumberFormatException has not been caught: " + bd.toString());
        } catch (NumberFormatException e) {}
    } 
 
    /** 
     * 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;
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
    public final static boolean compareTo(Object object, Object attribute, String key, NSDictionary params){
        if(attribute instanceof Number){
            String sign = (String)params.objectForKey("Operator");
            String number = (String)params.objectForKey("RightOperand");
            BigDecimal left = new BigDecimal(((Number)attribute).doubleValue());
            BigDecimal right = new BigDecimal(number);
            int comparisonValue=left.compareTo(right);
 
            if(sign.equals(GSVNumberMethods.EQUAL)){
                return(comparisonValue==0);
            } else if(sign.equals(GSVNumberMethods.NOT_EQUAL)){
                return(comparisonValue!=0);
            } else if(sign.equals(GSVNumberMethods.GREATER_THAN)){
                return(comparisonValue==1);
            } else if(sign.equals(GSVNumberMethods.GREATER_EQUAL)){
                return(comparisonValue==1 || comparisonValue==0);
            } else if(sign.equals(GSVNumberMethods.LESS_THAN)){
                return(comparisonValue==-1);
            } else if(sign.equals(GSVNumberMethods.LESS_EQUAL)){
                return(comparisonValue==-1 || comparisonValue==0);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: compareTo, precision, scale, setScale, stripTrailingZeros
    bd = normalize(bd, true);
    return bd == null ? null : new HiveDecimal(bd);
  } 
 
  public static HiveDecimal create(BigInteger bi) {
    BigDecimal bd = normalize(new BigDecimal(bi), true);
    return bd == null ? null : new HiveDecimal(bd);
  } 
 
  public static HiveDecimal create(int i) {
    return new HiveDecimal(new BigDecimal(i));
  } 
 
  public static HiveDecimal create(long l) {
    return new HiveDecimal(new BigDecimal(l));
  } 
 
  @Override 
  public String toString() {
     return bd.toPlainString();

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 BigDecimal Questions & Answers:

See Code Examples for Java 8 BigDecimal Methods: