Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use BigDecimal in Java

1 Answer

0 votes
package javaapplication1;
 
import java.math.BigDecimal;

public class JavaApplication1 {
 
    public static void main(String[] args) {
  
        double d = 3.14;
        BigDecimal a = new BigDecimal(d);
        BigDecimal b = new BigDecimal("1");
        BigDecimal c = new BigDecimal("0.0000000001");
       
        BigDecimal x = b.divide(a, 9, BigDecimal.ROUND_FLOOR);
               
        BigDecimal y = b.add(c);
        
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(x);
        System.out.println(y);
    }
}
 
/*
    
run:
    
3.140000000000000124344978758017532527446746826171875
1
1E-10
0.318471337
1.0000000001
    
*/

 



answered Nov 2, 2016 by avibootz

Related questions

1 answer 106 views
106 views asked Jul 24, 2022 by avibootz
2 answers 176 views
176 views asked Jul 25, 2019 by avibootz
2 answers 97 views
1 answer 94 views
1 answer 91 views
1 answer 81 views
81 views asked Jun 3, 2024 by avibootz
1 answer 107 views
...