createFormatter static method

NumberFormat createFormatter(
  1. PrecisionModel precisionModel
)

Creates the NumberFormat used to write doubles with a sufficient number of decimal places.

@param precisionModel the PrecisionModel used to determine the number of decimal places to write. @return a NumberFormat that write double s without scientific notation.

Implementation

static NumberFormat createFormatter(PrecisionModel precisionModel) {
  // the default number of decimal places is 16, which is sufficient
  // to accommodate the maximum precision of a double.
  int decimalPlaces = precisionModel.getMaximumSignificantDigits();
  // specify decimal separator explicitly to avoid problems in other locales
//    NumberFormatSymbols symbols = NumberFormatSymbols();
//    symbols.setDecimalSeparator('.');
  String fmtString =
      "0" + (decimalPlaces > 0 ? "." : "") + stringOfChar('#', decimalPlaces);
  return NumberFormat(fmtString);
}