Limit 2 decimal for Economy plugin

Discussion in 'Plugin Development' started by Emphytos, Mar 29, 2012.

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

    Emphytos

    Hi every body,

    I maded a economy plugin, but I add cents, so I convert int to double.

    All works on my local server, but on my debian server I've this error

    This is my function GetPlayerValue

    PHP:
        public static Double GetPlayerValue(String player)
        {
            
    double d values.get(GetPlayerIndex(player));
           
            
    DecimalFormat calculTotal = new DecimalFormat("#####.##");                 
            return 
    Double.parseDouble(calculTotal.format(d));
        }
     
        public static 
    int GetPlayerIndex(String player)
        {
            return 
    players.indexOf(player);
        }
    Can you help me ?
    Thanks
     
  2. Offline

    dsmyth1915

    Caused by: java.lang.NumberFormatException: For input string: "223,8"

    Keep looking around, maybe its a config or a problem with you code.
     
  3. Offline

    Father Of Time

    Code:
        public Double FormatMoney( Double value )
        {
            DecimalFormat df = new DecimalFormat("###,###,###.##");
            return df.format( value );
        }
     
  4. Offline

    dillyg10

    why are you returning a double object, not a double variable?
    it should be
    Code:java
    1.  
    2. public static double GetPlayerValue(String player)
    3.  
     
  5. Offline

    dsmyth1915

    Dilly is right, instead of using Double which returns objects, return double (lowercase d) to return floating variables. As for father of times post, I'm not familiar with DecimalFormat.
     
  6. Offline

    dillyg10

    Oh, and limiting it to 2 decimal places is somewhat tricky, you need to do.
    Code:java
    1.  
    2. double myDouble = 2.456
    3. double myDoubleMultiplided = myDouble*10
    4. double myDoubleRounded - Math.round(myDoubleMultiplied);
    5. double myDoubleDivided = myDoubleRounded / 10.0;
     
  7. Offline

    Emphytos

    Thanks all,
    dillyg10 it's works, thanks a lot :D
     
Thread Status:
Not open for further replies.

Share This Page