P
P
Pavel Subbotin2020-10-02 14:19:37
Java
Pavel Subbotin, 2020-10-02 14:19:37

How to round double in Java?

Is it possible for guys to make it so that if double has only an integer part, then it was displayed without ".0" at the end?

5f770c619a623097362647.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2020-10-02
@Comet2033

public static void print(double d) {
        if (d == (long) d) {
            System.out.println((long) d);
        } else {
            System.out.println(d);
        }
 }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question