Output Formatting

0

So guys, I was "futucando" in java, but I had a question. How do I format a number that is in a method?

For example:

Code snippet:

JOptionPane.showMessageDialog(null,brand+ "Saldo atual de " +cliente1.getID()+" :"
+ "\n"+cliente1.getBalance());

This code prints in the format 0000.0 but I wanted to remove this last decimal place, I already tried using % .f and % .db , but it did not work!

How do I get this .0 view?

Note: The getBalance method is a common method of a private double.

    
asked by anonymous 05.03.2016 / 22:42

1 answer

1

If you are working with four leading zeros, you can use the following expression: %04.0f it indicates that the left side of the comma should be filled with four zeros and the right side should not contain numbers, ie no decimal part .

See the example:

double valor = 0000.0;

JOptionPane.showMessageDialog(null, String.format("Valor: %04.0f", valor));

Output:

  

Value: 0000

Source: link

    
06.03.2016 / 00:14