Java 2 Decimals

[Solved] Java 2 Decimals | Swift - Code Explorer | yomemimo.com
Question : java double 2 decimal

Answered by : lars-vrlpys7wml88

String result = String.format("%.2f", value);

Source : https://stackoverflow.com/questions/2808535/round-a-double-to-2-decimal-places | Last Update : Mon, 08 Jun 20

Question : how to set 2 decimal places in java

Answered by : poised-polecat-oorg1f3djyrm

DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));

Source : https://stackoverflow.com/questions/2538787/how-to-print-a-float-with-2-decimal-places-in-java | Last Update : Wed, 12 Aug 20

Question : specify decimal places java

Answered by : bissallah-ahmed-ekele-jr

double test = 12.15;
DecimalFormat df = new DecimalFormat("#.0");
System.out.println(df.format(test)); // Console: 12.2
// # - prints a digit if provided, nothing otherwise
// . - indicates where to put the decimal seperator
// 0 - prints a digit if provided, 0 otherwise

Source : https://www.baeldung.com/java-decimalformat | Last Update : Tue, 05 Jan 21

Question : decimals java

Answered by : manuel-barril-rodrguezarana

// Java Program to Round a Number to n Decimal Places
// using format() Method
 
// Importing required classes
import java.io.*;
 
// Main class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
        // Declaring and initializing a double number
        double number = 3.141341435;
 
        // Rounding number to 2 decimal places
        // using format method
        System.out.format("%.2f", number);
    }
}

Source : https://www.geeksforgeeks.org/java-program-to-round-a-number-to-n-decimal-places/ | Last Update : Wed, 13 Jul 22

Question : how to get 2 decimal places in java

Answered by : kushal

total = (double) 100 / listMember.size();
DecimalFormat df = new DecimalFormat("#.##");
String dx = df.format(total);
total = Double.valueOf(dx);

Source : | Last Update : Sat, 07 Aug 21

Question : java 2 decimals

Answered by : greedy-goblin

double res = Math.round(a * 100) / 100;

Source : | Last Update : Thu, 24 Dec 20

Answers related to java 2 decimals

Code Explorer Popular Question For Swift