PrecisionModel other = (PrecisionModel) o; int sigDigits = getMaximumSignificantDigits(); int otherSigDigits = other.getMaximumSignificantDigits(); return (new Integer(sigDigits)).compareTo(new Integer(otherSigDigits));
/** * Creates the <code>DecimalFormat</code> used to write <code>double</code>s * with a sufficient number of decimal places. * *@param precisionModel the <code>PrecisionModel</code> used to determine * the number of decimal places to write. *@return a <code>DecimalFormat</code> that write <code>double</code> * s without scientific notation. */ private static DecimalFormat createFormatter(PrecisionModel precisionModel) { // the default number of decimal places is 16, which is sufficient // to accomodate the maximum precision of a double. int decimalPlaces = precisionModel.getMaximumSignificantDigits(); // specify decimal separator explicitly to avoid problems in other locales DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); String fmtString = "0" + (decimalPlaces > 0 ? "." : "") + stringOfChar('#', decimalPlaces); return new DecimalFormat(fmtString, symbols); }
public static NumberFormat format(PrecisionModel pm) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setNaN("NaN"); DecimalFormat f = new DecimalFormat(); f.setDecimalFormatSymbols(symbols); if (pm == null) { f.setMaximumFractionDigits(0); return f; } f.setMinimumFractionDigits(0); f.setMaximumFractionDigits(pm.getMaximumSignificantDigits()); return f; }
PrecisionModel other = (PrecisionModel) o; int sigDigits = getMaximumSignificantDigits(); int otherSigDigits = other.getMaximumSignificantDigits(); return (new Integer(sigDigits)).compareTo(new Integer(otherSigDigits));
/** * Creates the <code>DecimalFormat</code> used to write <code>double</code>s * with a sufficient number of decimal places. * *@param precisionModel the <code>PrecisionModel</code> used to determine * the number of decimal places to write. *@return a <code>DecimalFormat</code> that write <code>double</code> * s without scientific notation. */ private static DecimalFormat createFormatter(PrecisionModel precisionModel) { // the default number of decimal places is 16, which is sufficient // to accomodate the maximum precision of a double. int decimalPlaces = precisionModel.getMaximumSignificantDigits(); // specify decimal separator explicitly to avoid problems in other locales DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); String fmtString = "0" + (decimalPlaces > 0 ? "." : "") + stringOfChar('#', decimalPlaces); return new DecimalFormat(fmtString, symbols); }