[Weird] Totaling up bank accounts command

Discussion in 'Plugin Development' started by Xemos, Jul 2, 2012.

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

    Xemos

    I am trying to make a command that totals up bank accounts in a bank, stores the total in the config for the bank, then totals up the grand total for all banks, and also stores that.

    But I am getting a few weird glitches and don't see why.

    Code:java
    1.  
    2. private boolean doUpdate(Player player){
    3.  
    4. List<String> banks = config.getStringList("Banks.List");
    5. List<String> accHolders = null;
    6. double total = 0;
    7. String member = "";
    8. String region ="";
    9. String ID = "";
    10. double sum =0;
    11.  
    12.  
    13.  
    14. for (int x = 0; x < banks.size(); x++){
    15. ID = banks.get(x);
    16. accHolders = config.getStringList("Banks." + ID + ".Members");
    17. for (int y = 0; y < accHolders.size(); y++){
    18. member = accHolders.get(y);
    19. sum += (getHoldings(ID + "-" + member));
    20. }
    21. region = config.getString("Banks." + ID + ".Region");
    22. config.set("Region", region);
    23. config.set("Location." + region, ID);
    24.  
    25. config.set("Banks." + ID + ".Total", sum);
    26. plugin.saveConfig();
    27. total += sum;
    28. sum = 0;
    29. accHolders = null;
    30. }
    31. config.set("Banks.Total", total);
    32. player.sendMessage("The bank totals have been recalculated.");
    33. plugin.saveConfig();
    34.  
    35.  
    36.  
    37. return true;
    38. }
    39.  


    Some totals that i get:
    Code:
     
        Total: 1.1086279669999996E7
        Total: 1931314.2599999998
        Total: 1.549421606E7
        Total: 274858.02 
     
    
    I can fix extra decimals rather easy, but why is it putting it in power notation?


    So here is where i sit. Any help is much appreciated

    *note as i was writing this, i solved my regions error*
     
  2. Offline

    Jnorr44

    wait, are you trying to add up money, or add up the amount of accounts? Because I don't see any calculations for an amount of money. I really cant read this code, what is banks.size() doing? you haven't declared banks...
     
  3. Offline

    Xemos

    Bukkit forums hath failed me and i never got notified of the reply.. I attempted a botched fix to no avail.

    Lets see if i can post it better with a code box
    PHP:
    private boolean doUpdate(Player player){
           
            List<
    Stringbanks config.getStringList("Banks.List");
            List<
    StringaccHolders null;
            
    double total 0;
            
    String member "";
            List<
    Stringregion null;
            
    String ID "";
            
    double sum =0;
            
    DecimalFormat nf = (DecimalFormatNumberFormat.getInstance(Locale.US);
           
           
           
            for (
    int x 0banks.size(); x++){
                
    ID banks.get(x);
                
    accHolders config.getStringList("Banks." ID ".Members");
                for (
    int y 0accHolders.size(); y++){
                    
    member accHolders.get(y);
                    
    sum += (getHoldings(ID "-" member));
                }
                
    region.set(x,config.getString("Banks." ID ".Region"));
               
                
    config.set("Location." region.get(x), ID);
               
                
    config.set("Banks." ID ".Total"nf.format(sum));
                
    plugin.saveConfig();
                
    total += sum;
                
    sum 0;
                
    accHolders null;
            }
            
    config.set("Region"region);
            
    config.set("Banks.Total"total);
            
    player.sendMessage("The bank totals have been recalculated.");
            
    plugin.saveConfig();
           
           
           
            return 
    true;
        }
    Number format was my attempt at a fix, but it doesn't work.

    How it works:
    It gets the list of all bank accounts on the server:
    Code:
    List<String> banks = config.getStringList("Banks.List");
    It then does a loop based off the number of banks
    Code:
    for (int x = 0; x < banks.size(); x++){
    It then loops over for each account owner in said bank, getting the money they have and adding it up
    Code:
    accHolders = config.getStringList("Banks." + ID + ".Members");
    for (int y = 0; y < accHolders.size(); y++){
    member = accHolders.get(y);
    sum += (getHoldings(ID + "-" + member));
    }

    Sets the bank's total with this
    Code:
    config.set("Banks." + ID + ".Total", nf.format(sum))
    The server's total with this:
    Code:
     config.set("Banks.Total", total);

    Hope that clarifies it up. Like said the numbers seem right but the E notation makes it fail, Trying to store it as a string with 243634576.20 or 23409.39 ect ect.
     
Thread Status:
Not open for further replies.

Share This Page