public FormattedNumber[] formatSame( double[] vals, UnitsConstants unitType, ScaleConstants scale, Locale locale, FormatSpecifics specifics) { FormattedNumber[] res; NumberFormat fmt; UnitNumber tmpNum; double[] newVals; double average; ScaleConstants targScale; res = new FormattedNumber[vals.length]; if (vals.length == 0) { return res; } average = ArrayUtil.average(vals); tmpNum = new UnitNumber(average, unitType, scale); targScale = this.findGoodLookingScale(tmpNum.getBaseValue()); newVals = new double[vals.length]; for (int i = 0; i < vals.length; i++) { tmpNum = new UnitNumber(vals[i], unitType, scale); newVals[i] = this.getTargetValue(tmpNum.getBaseValue(), targScale); } if (specifics == null) { fmt = UnitsUtil.getNumberFormat(newVals, locale); } else { fmt = this.getSpecificFormatter(specifics, locale); } for (int i = 0; i < vals.length; i++) { res[i] = this.createFormattedValue(newVals[i], targScale, fmt); } return res; }
public FormattedNumber format(UnitNumber val, Locale locale, FormatSpecifics specifics) { NumberFormat fmt; BigDecimal baseVal; double newVal; ScaleConstants targScale; baseVal = val.getBaseValue(); targScale = this.findGoodLookingScale(baseVal); newVal = this.getTargetValue(baseVal, targScale); if (specifics == null) { fmt = UnitsUtil.getNumberFormat(new double[] {newVal}, locale); } else { fmt = this.getSpecificFormatter(specifics, locale); } return this.createFormattedValue(newVal, targScale, fmt); }