user2834525
user2834525

Reputation: 1

Formatting a decimal with java.text.DecimalFormat

I'm trying to format the number 0.14000 using java.text.DecimalFormat in order to obtain the value 0.14. Using the format #.## I get 140. What's wrong?

Upvotes: 0

Views: 1114

Answers (1)

Cortex
Cortex

Reputation: 684

Please try

DecimalFormat decimalFormat = new DecimalFormat("0.00");

Example:

import java.text.DecimalFormat;

public class MyDecimalFormat {
    public static void main(String[] args) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        System.out.println( decimalFormat.format( 0.14000 ) );
    }
}

Output:

0.14

Upvotes: 1

Related Questions