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); } } }
public ScientificRenderer(int sigfigs) { sigfigs = Math.min(sigfigs, 6); if (format instanceof DecimalFormat) { String pattern = "0.0"; // $NON-NLS-1$ for (int i = 0; i < sigfigs - 1; i++) { pattern += "0"; // $NON-NLS-1$ } pattern += "E0"; // $NON-NLS-1$ ((DecimalFormat) format).applyPattern(pattern); } }
// Recompute the locale-based formatter. void setLocale(Locale loc) { if (type == null) ; else if (type.equals("number")) { formatClass = java.lang.Number.class; if (style == null) format = NumberFormat.getInstance(loc); else if (style.equals("currency")) format = NumberFormat.getCurrencyInstance(loc); else if (style.equals("percent")) format = NumberFormat.getPercentInstance(loc); else if (style.equals("integer")) { NumberFormat nf = NumberFormat.getNumberInstance(loc); nf.setMaximumFractionDigits(0); nf.setGroupingUsed(false); format = nf; } else { format = NumberFormat.getNumberInstance(loc); DecimalFormat df = (DecimalFormat) format; df.applyPattern(style); } } else if (type.equals("time") || type.equals("date")) { formatClass = java.util.Date.class; int val = DateFormat.DEFAULT; boolean styleIsPattern = false; if (style == null) ; else if (style.equals("short")) val = DateFormat.SHORT; else if (style.equals("medium")) val = DateFormat.MEDIUM; else if (style.equals("long")) val = DateFormat.LONG; else if (style.equals("full")) val = DateFormat.FULL; else styleIsPattern = true; if (type.equals("time")) format = DateFormat.getTimeInstance(val, loc); else format = DateFormat.getDateInstance(val, loc); if (styleIsPattern) { SimpleDateFormat sdf = (SimpleDateFormat) format; sdf.applyPattern(style); } } else if (type.equals("choice")) { formatClass = java.lang.Number.class; if (style == null) throw new IllegalArgumentException("style required for choice format"); format = new ChoiceFormat(style); } }
static { df = new DecimalFormat(); df.applyPattern("#.##"); }