コード例 #1
0
ファイル: NumberUtil.java プロジェクト: arunwizz/optiq
  static {
    // TODO: DecimalFormat uses ROUND_HALF_EVEN, not ROUND_HALF_UP
    // Float: precision of 7 (6 digits after .)
    floatFormatter = new DecimalFormat();
    floatFormatter.applyPattern("0.######E0");

    // Double: precision of 16 (15 digits after .)
    doubleFormatter = new DecimalFormat();
    doubleFormatter.applyPattern("0.###############E0");

    bigIntTenPow = new BigInteger[20];
    bigIntMinUnscaled = new BigInteger[20];
    bigIntMaxUnscaled = new BigInteger[20];

    for (int i = 0; i < bigIntTenPow.length; i++) {
      bigIntTenPow[i] = bigIntTen.pow(i);
      if (i < 19) {
        bigIntMaxUnscaled[i] = bigIntTenPow[i].subtract(BigInteger.ONE);
        bigIntMinUnscaled[i] = bigIntMaxUnscaled[i].negate();
      } else {
        bigIntMaxUnscaled[i] = BigInteger.valueOf(Long.MAX_VALUE);
        bigIntMinUnscaled[i] = BigInteger.valueOf(Long.MIN_VALUE);
      }
    }
  }
コード例 #2
0
 private NumberFormat getFormat() {
   NumberFormat f = DecimalFormat.getNumberInstance(Locales.getCurrent());
   f.setMinimumFractionDigits(2);
   f.setMaximumFractionDigits(2);
   return f;
 }