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,880 questions

51,806 answers

573 users

How to get the decimal part of a number in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        double d = 3.1415;

        System.out.println(d - (int)d);
    }
}




/*
run:

0.14150000000000018

*/

 



answered Jun 14, 2022 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        double d = 3.1415;
        
        String s = String.valueOf(d);
        
        int index = s.indexOf(".");

        System.out.println(s.substring(index));
        System.out.println(s.substring(index + 1));
    }
}




/*
run:

.1415
1415

*/

 



answered Jun 14, 2022 by avibootz

Related questions

4 answers 222 views
2 answers 171 views
2 answers 166 views
1 answer 139 views
1 answer 101 views
1 answer 116 views
...