Solved I have a Problem with a counter

Discussion in 'Plugin Development' started by Schlurp, Jan 14, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Schlurp

    my problem is that i get Numbers like this:
    23.57003300000009
    23.67003300000009
    23.77003300000009
    23.87003300000012
    but i want to get
    23.5
    23.6
    23.7
    23.8
    and my code is
    Code:
    double a = 0.1;
                    double count = Main.cookies.getDouble(p.getName() + ".Cookies");
                    count += a;
                    Main.cookies.set(p.getName() + ".Cookies", count);
                    p.sendmessage(count + "Cookies");
                    try {
                        Main.cookies.save(Main.file1);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
    Please help me
     
  2. Offline

    JanTuck

  3. Offline

    RelicObject

    I had to do something similar to this, and came across this:
    Code:
    
    
    
    NumberFormat formatter = new DecimalFormat("#0.0");
    double a = 0.1;
    double count = Main.cookies.getDouble(p.getName() + ".Cookies");
    count += a;
    String cookieCount = formatter.format(count);
    Main.cookies.set(p.getName() + ".Cookies", cookieCount);
    p.sendmessage("You have [" + cookieCount + "] Cookies!");
    try {
    Main.cookies.save(Main.file1);
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    
     
  4. Offline

    JanTuck

    I did not want to spoonfeed him so i gave him a link to a site that states pretty much what you wrote.

    Sendt fra min ALE-L21 med Tapatalk
     
  5. Offline

    RelicObject

    Thread wasnt marked as solved, i already knew the answer so did not check the stackoverflow and just decided to tell him how, he probably would have copy+pasted from the stackoverflow answer anyway :p
     
    JanTuck likes this.
  6. Offline

    Schlurp

    thx to you both for the help :)
     
Thread Status:
Not open for further replies.

Share This Page