use of com.ibm.icu.text.NumberFormat in project es6draft by anba.
the class NumberFormatConstructor method PartitionNumberPattern.
/**
* PartitionNumberPattern(numberFormat, x)
*
* @param numberFormatObj
* the number format object
* @param x
* the number value
* @return the formatted number object
*/
private static List<Map.Entry<String, String>> PartitionNumberPattern(NumberFormatObject numberFormat, double x) {
if (x == -0.0) {
// -0 is not considered to be negative, cf. step 3a
x = +0.0;
}
ArrayList<Map.Entry<String, String>> parts = new ArrayList<>();
NumberFormat numFormat = numberFormat.getNumberFormat();
AttributedCharacterIterator iterator = numFormat.formatToCharacterIterator(x);
StringBuilder sb = new StringBuilder();
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
sb.append(ch);
if (iterator.getIndex() + 1 == iterator.getRunLimit()) {
Iterator<Attribute> keyIterator = iterator.getAttributes().keySet().iterator();
String key;
if (keyIterator.hasNext()) {
key = fieldToString((NumberFormat.Field) keyIterator.next(), x);
} else {
key = "literal";
}
String value = sb.toString();
sb.setLength(0);
parts.add(new AbstractMap.SimpleImmutableEntry<>(key, value));
}
}
return parts;
}
use of com.ibm.icu.text.NumberFormat in project es6draft by anba.
the class PluralRulesObject method toFixedDecimal.
@SuppressWarnings("deprecation")
com.ibm.icu.text.PluralRules.FixedDecimal toFixedDecimal(double n) {
NumberFormat nf = getNumberFormat();
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(DecimalFormat.FRACTION_FIELD);
nf.format(n, sb, fp);
int v = fp.getEndIndex() - fp.getBeginIndex();
long f = 0;
if (v > 0) {
ParsePosition pp = new ParsePosition(fp.getBeginIndex());
f = nf.parse(sb.toString(), pp).longValue();
}
return new com.ibm.icu.text.PluralRules.FixedDecimal(n, v, f);
}
Aggregations