protected String expandNumber(double number) { this.rbnf.setDefaultRuleSet(cardinalRule); return this.rbnf.format(number); }
protected String expandOrdinal(double number) { this.rbnf.setDefaultRuleSet(ordinalRule); return this.rbnf.format(number); }
protected String expandYear(double number) { this.rbnf.setDefaultRuleSet(yearRule); return this.rbnf.format(number); }
protected String expandNumber(double number) { this.rbnf.setDefaultRuleSet(cardinalRule); return this.rbnf.format(number); }
protected String expandOrdinal(double number) { this.rbnf.setDefaultRuleSet(ordinalRule); return this.rbnf.format(number); }
RuleBasedNumberFormat nf = new RuleBasedNumberFormat(Locale.UK, RuleBasedNumberFormat.SPELLOUT); for(int i = 0; i <= 30; i++) { System.out.println(i + " -> "+nf.format(i, "%spellout-ordinal")); }
/** * <strong style="font-family: helvetica; color: red;">NEW</strong> * Implement com.ibm.icu.text.NumberFormat: * Format a BigInteger. * @stable ICU 2.0 */ @Override public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) { return format(new com.ibm.icu.math.BigDecimal(number), toAppendTo, pos); }
/** * <strong style="font-family: helvetica; color: red;">NEW</strong> * Implement com.ibm.icu.text.NumberFormat: * Format a BigDecimal. * @stable ICU 2.0 */ @Override public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) { return format(new com.ibm.icu.math.BigDecimal(number), toAppendTo, pos); }
protected String expandOrdinal(double number) { this.rbnf.setDefaultRuleSet(ordinalRule); return this.rbnf.format(number); }
protected String expandNumber(double number) { this.rbnf.setDefaultRuleSet(cardinalRule); return this.rbnf.format(number); }
/** * Formats the specified number using the formatter's default rule set. * (The default rule set is the last public rule set defined in the description.) * @param number The number to format. * @param toAppendTo A StringBuffer that the result should be appended to. * @param ignore This function doesn't examine or update the field position. * @return toAppendTo * @stable ICU 2.0 */ @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition ignore) { // this is one of the inherited format() methods. Since it doesn't // have a way to select the rule set to use, it just uses the // default one // Note, the BigInteger/BigDecimal methods below currently go through this. if (toAppendTo.length() == 0) { toAppendTo.append(adjustForContext(format(number, defaultRuleSet))); } else { // appending to other text, don't capitalize toAppendTo.append(format(number, defaultRuleSet)); } return toAppendTo; }
/** * Formats the specified number using the formatter's default rule set. * (The default rule set is the last public rule set defined in the description.) * (If the specified rule set specifies a master ["x.0"] rule, this function * ignores it. Convert the number to a double first if you ned it.) This * function preserves all the precision in the long-- it doesn't convert it * to a double. * @param number The number to format. * @param toAppendTo A StringBuffer that the result should be appended to. * @param ignore This function doesn't examine or update the field position. * @return toAppendTo * @stable ICU 2.0 */ @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition ignore) { // this is one of the inherited format() methods. Since it doesn't // have a way to select the rule set to use, it just uses the // default one if (toAppendTo.length() == 0) { toAppendTo.append(adjustForContext(format(number, defaultRuleSet))); } else { // appending to other text, don't capitalize toAppendTo.append(format(number, defaultRuleSet)); } return toAppendTo; }
/** * Formats the specified number according to the specified rule set. * @param number The number to format. * @param ruleSet The name of the rule set to format the number with. * This must be the name of a valid public rule set for this formatter. * @return A textual representation of the number. * @stable ICU 2.0 */ public String format(double number, String ruleSet) throws IllegalArgumentException { if (ruleSet.startsWith("%%")) { throw new IllegalArgumentException("Can't use internal rule set"); } return adjustForContext(format(number, findRuleSet(ruleSet))); }
/** * Formats the specified number according to the specified rule set. * (If the specified rule set specifies a master ["x.0"] rule, this function * ignores it. Convert the number to a double first if you ned it.) This * function preserves all the precision in the long-- it doesn't convert it * to a double. * @param number The number to format. * @param ruleSet The name of the rule set to format the number with. * This must be the name of a valid public rule set for this formatter. * @return A textual representation of the number. * @stable ICU 2.0 */ public String format(long number, String ruleSet) throws IllegalArgumentException { if (ruleSet.startsWith("%%")) { throw new IllegalArgumentException("Can't use internal rule set"); } return adjustForContext(format(number, findRuleSet(ruleSet))); }
@Override public synchronized Query makeQuery() throws Exception { return parser.parse("" + rnbf.format(getNextCounter()) + ""); }
@Override public synchronized DocData getNextDocData(DocData docData) throws NoMoreDataException, IOException { docData.clear(); // store the current counter to avoid synchronization later on long curCounter; synchronized (this) { curCounter = counter; if (counter == Long.MAX_VALUE){ counter = Long.MIN_VALUE;//loop around } else { ++counter; } } docData.setBody(rnbf.format(curCounter)); docData.setName("doc_" + String.valueOf(curCounter)); docData.setTitle("title_" + String.valueOf(curCounter)); docData.setDate(new Date()); return docData; }
/** * Method to format an amount using a custom rule set. * Current rule sets available: * * en_US * %dollars-and-cents - 1,225.25 becomes "one thousand two hundred twenty five dollars and twenty five cents" (useful for checks) * %dollars-and-hundreths - 1,225.25 becomes "one thousand two hundred twenty five and 25/00" (alternate for checks) * * @param amount - the amount to format * @param ruleSet - ruleSet to use * @param rule - the name of the rule set to use (e.g., %dollars-and-hundredths) * @param locale - the Locale * @return formatted string or an empty string if there was an error */ public static String formatRuleBasedAmount(double amount, String ruleSet, String rule, Locale locale) { RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(ruleSet, locale); String result = ""; try { result = formatter.format(amount, rule != null ? rule : formatter.getDefaultRuleSetName()); } catch (Exception e) { Debug.logError(e, "Failed to format amount " + amount + " using rule " + rule, module); } return result; }
/** * <strong style="font-family: helvetica; color: red;">NEW</strong> * Implement com.ibm.icu.text.NumberFormat: * Format a BigDecimal. * @stable ICU 2.0 */ @Override public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) { if (MIN_VALUE.compareTo(number) >= 0 || MAX_VALUE.compareTo(number) <= 0) { // We're outside of our normal range that this framework can handle. // The DecimalFormat will provide more accurate results. return getDecimalFormat().format(number, toAppendTo, pos); } if (number.scale() == 0) { return format(number.longValue(), toAppendTo, pos); } return format(number.doubleValue(), toAppendTo, pos); }