/** * Produces a text formula representation of this unit. */ public String printUnit() { StringBuffer times = new StringBuffer(); if (getMultiplier() != 0d) { if (getMultiplier() != 1d) { times.append(StringTools.toString(getMultiplier())); } StringBuffer pow = new StringBuffer(); pow.append(kind != null ? kind.getSymbol() : "undefined"); String prefix = getPrefix(); if ((prefix.length() > 0) && !prefix.startsWith("10")) { pow.insert(0, prefix); } else if (getScale() != 0) { pow = FormulaCompiler.times(FormulaCompiler.pow(Integer.valueOf(10), getScale()), pow); } times = FormulaCompiler.times(times, pow); } if ((offset != null) && (offset.doubleValue() != 0d)) { times = FormulaCompiler.sum(StringTools.toString(offset.doubleValue()), times); } return FormulaCompiler.pow(times, StringTools.toString(getExponent())).toString(); }
/** * * @param u * @return */ public static String toHTML(Unit u) { StringBuffer times = new StringBuffer(); if (u.getMultiplier() != 0) { if (u.getMultiplier() != 1) { times.append(StringTools.toString(u.getMultiplier())); } StringBuffer pow = new StringBuffer(); pow.append(u.getKind().getSymbol()); String prefix = u.getPrefix(); if (prefix.length() > 0 && !prefix.startsWith("10")) { pow.insert(0, prefix); } else if (u.getScale() != 0) { pow.insert(0, ' '); pow = HTMLFormula.times(HTMLFormula.pow(Integer.valueOf(10), u .getScale()), pow); } times = HTMLFormula.times(times, pow); } if (u.getOffset() != 0) { times = HTMLFormula.sum(StringTools.toString(u.getOffset()), times); } return HTMLFormula.pow(times, StringTools.toString(u.getExponent())) .toString(); }
/** * * @param u * @return */ @SuppressWarnings("deprecation") public static String toHTML(Unit u) { StringBuffer times = new StringBuffer(); if (u.getMultiplier() != 0) { if (u.getMultiplier() != 1) { times.append(StringTools.toString(u.getMultiplier())); } StringBuffer pow = new StringBuffer(); pow.append(u.getKind().getSymbol()); String prefix = u.getPrefix(); if (prefix.length() > 0 && !prefix.startsWith("10")) { pow.insert(0, prefix); } else if (u.getScale() != 0) { pow.insert(0, ' '); pow = HTMLFormula.times(HTMLFormula.pow(Integer.valueOf(10), u .getScale()), pow); } times = HTMLFormula.times(times, pow); } if (u.getOffset() != 0) { times = HTMLFormula.sum(StringTools.toString(u.getOffset()), times); } return HTMLFormula.pow(times, StringTools.toString(u.getExponent())) .toString(); }