Solved Block double zero

Discussion in 'Plugin Development' started by ScopeTowel, Apr 10, 2020.

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


    Hello everyone, I have a big problem, basically I put a double and I would like the player to not put more than 2 zero after the decimal point. Style, if the player writes 0.9999999, then it won't work, but if he writes 0.99, it will work
  2. Offline


    If the input is a string (e.g chat input), you can just check the length of the string after the period. If applicable, you could use the DecimalFormatter to make sure you only get 2 decimals, no matter how many the user gave.

    Example DecimalFormat usage;
    2. DecimalFormat df = new DecimalFormat("#0.00");
    3. double someNumber = 0.99999;
    5. System.out.println(df.format(someNumber)); // This will output 1.00 because it rounds up/down based on the input.
    Last edited: Apr 10, 2020
  3. Offline


Thread Status:
Not open for further replies.

Share This Page