Home > Blockchain >  how to remove a whole number part in java?
how to remove a whole number part in java?

Time:10-30

I have a double which value is set to 0.00. I need the print statement to display it as "$.00". So the whole number part is not displayed

Tried using String.format() method as well as substring method but it did not bring me anywhere...any help is appreciated, thank you!

CodePudding user response:

Try this:

double value = 0;
DecimalFormat format = new DecimalFormat("$.00");
System.out.println(format.format(value));

CodePudding user response:

As I understand the question:

Try that one

        double amount = 0;
        System.out.println("$"   amount);
  • Related