java double 2 decimal
Java
String result = String.format("%.2f", value);package com.mkyong;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalExample {
private static DecimalFormat df2 = new DecimalFormat("#.##");
public static void main(String[] args) {
double input = 3.14159265359;
System.out.println("double : " + input);
System.out.println("double : " + df2.format(input)); //3.14
// DecimalFormat, default is RoundingMode.HALF_EVEN
df2.setRoundingMode(RoundingMode.DOWN);
System.out.println("\ndouble : " + df2.format(input)); //3.14
df2.setRoundingMode(RoundingMode.UP);
System.out.println("double : " + df2.format(input)); //3.15
}
}
Copy
Also in Java:
- Title
- how to return the lower of two values in one line java
- Category
- Java
- Title
- java localdate subtract two dates
- Category
- Java
- Title
- how to define an arraylist in java
- Category
- Java
- Title
- how to minimize jframe in java
- Category
- Java
- Title
- java observable to observer stack overflow
- Category
- Java
- Title
- priority queue in java
- Category
- Java
- Title
- how to pass parameters to xsl file
- Category
- Java
- Title
- nikita kaksharov
- Category
- Java
- Title
- java how to initialize an array
- Category
- Java
- Title
- java main method
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- java replace all xml decoding
- Category
- Java
- Title
- input java
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- how to use lambda in java
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- java http client eviction
- Category
- Java
- Title
- cordova cannot find symbol import com.google.firebase.iid.FirebaseMessagingService;
- Category
- Java
- Title
- java read file bufferedreader
- Category
- Java
- Title
- convert array of int to arraylist java
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- processing audio android
- Category
- Java
- Title
- iterate hashmap java
- Category
- Java
- Title
- java output array lists to file
- Category
- Java
- Title
- gradle require java version
- Category
- Java
- Title
- bufferedwriter doesn't write to file
- Category
- Java
- Title
- how to convert string to double in android studio
- Category
- Java
- Title
- java - get open ports
- Category
- Java
- Title
- searching in database using java
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- processing sound library
- Category
- Java
- Title
- iterator loop java
- Category
- Java
- Title
- determine if a given binary tree is a valid bst
- Category
- Java
- Title
- int to long java
- Category
- Java
- Title
- iterate through hashmap in java
- Category
- Java
- Title
- convert string to int java
- Category
- Java
- Title
- java get first char
- Category
- Java
- Title
- java how to print a string[]
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- set color of text for jlabel
- Category
- Java
- Title
- java read from file
- Category
- Java
- Title
- socket in java
- Category
- Java
- Title
- java round double to 2 decimal places
- Category
- Java
- Title
- java constructor genertic
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- initialiser une arraylist
- Category
- Java
- Title
- java random numbers in specific range
- Category
- Java
- Title
- charat(0).touppercase() java
- Category
- Java
- Title
- java display message
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- java bigdecimal compareto
- Category
- Java
- Title
- icon label java
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- déclarer un tableau en java
- Category
- Java
- Title
- How do you count characters in a string array in Java?
- Category
- Java
- Title
- java linked list iterator
- Category
- Java
- Title
- how to get the width and height of a string in java
- Category
- Java
- Title
- java break in foreach
- Category
- Java
- Title
- how to select a element in an arraylist java
- Category
- Java
- Title
- how to append to an array in java
- Category
- Java
- Title
- how to find powers in java
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- one line if statement java
- Category
- Java
- Title
- print out value java
- Category
- Java
- Title
- how to import jframe in java
- Category
- Java
- Title
- java string contains char
- Category
- Java
- Title
- generic method lambda java
- Category
- Java
- Title
- how to fill a list with a single value java
- Category
- Java
- Title
- get material of block bukkit
- Category
- Java
- Title
- hibernate onetone with mapsid
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- system.out.println shortcut
- Category
- Java
- Title
- java how to compare strings
- Category
- Java
- Title
- spring framework iterate
- Category
- Java
- Title
- how to create a method java
- Category
- Java
- Title
- trees in java
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- how to write a merge sort array method ni java
- Category
- Java
- Title
- how to install java 8 on terminal os
- Category
- Java
- Title
- reverse shuffle merge
- Category
- Java
- Title
- java io
- Category
- Java
- Title
- object orientation in java
- Category
- Java
- Title
- download spring
- Category
- Java
- Title
- processing play sound
- Category
- Java
- Title
- iterate through hashmap java
- Category
- Java
- Title
- StringBuilder java pop back
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- remove last character from string java
- Category
- Java
- Title
- java get current milliseconds
- Category
- Java
- Title
- java parse json
- Category
- Java
- Title
- java string to boolean
- Category
- Java
- Title
- null pointer exception java
- Category
- Java
- Title
- java add a list to a list
- Category
- Java
- Title
- how to access private vairable in java method
- Category
- Java
- Title
- arraylist to array java
- Category
- Java