Solved Balance format is wrong?

Discussion in 'Spigot Plugin Development' started by Lifeonblack, Jun 9, 2017.

  1. Hello so I have this kind of format
    Code (Java):
    public String commas(double amount) {
           DecimalFormat formatter = new DecimalFormat("###.00");
           String number = formatter.format(amount);
           return number;
         }
    but it shows like this.
    [​IMG]
     
  2. If you use # in the DecimalFormat it will only display something, if there is something to display.
    So if you are trying to display 0.00, you should use "##0.00".
    Your code should work fine for amounts higher then 0.
     
  3. I tested your code on a simple console output and that only happens when amount is equal to 0. I suggest adding something like this
    Code (Text):
    if(amount == 0) {
      number = "0.00";
    }
     
  4. oh well thanks didn't know about that info. :)