Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

How to Use the printf() Function in Java

public class Main{
    public static void main(String[] args) {
        double value = 2.3897;
        System.out.println(value);
        System.out.printf("%.2f" , value);
    }
}



/* Here, I am declaring a double type variable named value
and I am assigning 2.3897 to it.
Now when I use the println() function,
it prints the whole value with the 4 digits after the radix
point.

This is the output:
*/


// 2.3897
// 2.39
 
PREVIOUS NEXT
Tagged: #How #Use #Function #Java
ADD COMMENT
Topic
Name
6+8 =