Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java double to fixed decimal

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class DecimalExample {

    private static final DecimalFormat df = new DecimalFormat("0.00");

    public static void main(String[] args) {

        double input = 3.14159265359;

        System.out.println("double : " + input);
        System.out.println("double : " + df.format(input));    //3.14

        // DecimalFormat, default is RoundingMode.HALF_EVEN
        df.setRoundingMode(RoundingMode.DOWN);
        System.out.println("
double (RoundingMode.DOWN) : " + df.format(input));  //3.14

        df.setRoundingMode(RoundingMode.UP);
        System.out.println("double (RoundingMode.UP)  : " + df.format(input));    //3.15

    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: new hashmap java 
Java :: glide latest version android 
Java :: java how to generate guid 
Java :: java show error dialog 
Java :: java pause console 
Java :: calculate pi in java 
Java :: system.out.println 
Java :: find number of days between two local dates in java 8 
Java :: removeAll hard code 
Java :: java string format .2f 
Java :: java date to string yyyy-mm-dd 
Java :: bouble to bytes[] java 
Java :: set html text android java 
Java :: hql return new object from query 
Java :: android how to start a new activity on button click 
Java :: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory 
Java :: random between two numbers java 
Java :: youTubeInitializationResult gives SERVICE_MISSING error in android 
Java :: Java get list of keys Hashmap 
Java :: linear layout background color 
Java :: java how to center window 
Java :: java write a file line by line 
Java :: print line number java 
Java :: java multiplication table nested loop 
Java :: input string a list in java 
Java :: java check if directory exists 
Java :: how to test how many of one character is in a string java 
Java :: last day of month from localdate java 
Java :: multiply two strings 
Java :: how to get the last element of array in java 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =