0

I have to make this method round up a double which is fine but I need it to only round up the first number after the first decimal.

Example 83.2839783214 would be 83.3 here is the code I have so far I can't seem to figure out how exactly to implement it.

public double getPercentFull(){

double percent;

double p = (storage / capacity) * 100;

percent = (double)Math.round(p);

return percent;

  • The other post that is a duplicate doesn't answer my questions. Doing this for a class and have to write methods without importing. – Dane Muller May 04 '16 at 14:06
  • `((double) Math.round(x * 10)) / 10` which of course has no exact precision, floating point only approximates real numbers with a sum of (negative) powers of 2. – Joop Eggen May 04 '16 at 14:30
  • This worked thank you :D! After fooling around with it I found out that the more 0's you add the more decimals are displayed as well. – Dane Muller May 04 '16 at 15:05
  • Aaah, improved on the solution. Mind that 1,000,000 * 0.1 will not exactly be 100,000.0. For financial things use BigDecimal. – Joop Eggen May 04 '16 at 15:12

0 Answers0