The below code is giving very long numbers when I input 2, 3, 99 and probably more... Code: double temp = 1; double price = ((temp * 0.30) + temp) * input; I do the same math problem in my windows calculator and it turns out not being a super long number, is the java calculator broken? Heres my full code: Code: } else if (cmd.equals("buy")) { if (args.length >= 2) { String item = args[1]; int ammount = 1; if (args.length == 3) ammount = Integer.parseInt(args[2]); double temp = EcoData.getPrice(item); double price = ((temp * 0.30) + temp) * ammount; if (!(EcoData.getMoney(player.getName()) > price)) { send(player, "&c&lInsufishent Funds"); return; } if (price != 0) { send(player, "&2&lBought &7&l" + ammount + " " + item + "&2&l for $&7&l" + String.valueOf(price).replace(".0", "")); player.setItemInHand(new ItemStack(Material.AIR)); EcoData.takeMoney(player.getName(), price); player.getInventory().addItem(new ItemStack(Material.getMaterial(item), ammount)); } else send(player, "&c&lCan't Buy That Item"); return; } } Any help is awesome
double price = ((temp * 0.30) + temp) * input; temp = how much the item sells for input = how many items you want to buy * 0.30 = %30 I want to add %30 to how much the item sells for
Use 'temp * 1.3 * input' instead of messing with brackets. Not sure what the best way to round it is.
What you're doing will give you 130% of the item, however you could just use 1.3 * temp * input, since that's essentially what you're doing in the brackets (minus the "input" bit). To round it to the nearest tens, use: Code: BigDecimal bd = new BigDecimal(price).setScale(2, RoundingMode.HALF_EVEN); Then use BigDecimal#doubleValue().
Awesome, Thanks Code: double price = Double.parseDouble(new BigDecimal(EcoData.getPrice(item) * 1.3 * input).setScale(2, RoundingMode.HALF_EVEN).toString());
Eh, I'd use: Code: double price = new BigDecimal(EcoData.getPrice(item) * 1.3 * input).setScale(2, RoundingMode.HALF_EVEN).doubleValue();