Code example for BigDecimal

Methods: intValue, setScale

0
 
    // The system brightness can range from 0 to 255. To normalize this 
    // to the application's 0 to 100 brightness values, we lookup the 
    // configured minimum value and then normalize for the range 
    // minValue to 255. 
    BigDecimal d = new BigDecimal((systemBrightness - minValue)
        / (255.0 - minValue) * 100.0);
    d = d.setScale(0, BigDecimal.ROUND_HALF_EVEN);
    int normalizedBrightness = d.intValue();
 
    if (normalizedBrightness < 0) {
      // This can happen if another application sets the phone's brightness 
      // to a value lower than our configured minimum. 
      return 0; 
    } else { 
      return normalizedBrightness;
    } 
  } 
 
  /** 
   * Finds the phone's system brightness setting. Returns 0 if there is an error