本文整理汇总了C++中Formattable::setDecimalNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Formattable::setDecimalNumber方法的具体用法?C++ Formattable::setDecimalNumber怎么用?C++ Formattable::setDecimalNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formattable
的用法示例。
在下文中一共展示了Formattable::setDecimalNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execFormatTest
void DecimalFormatTest::execFormatTest(int32_t lineNum,
const UnicodeString &pattern, // Pattern
const UnicodeString &round, // rounding mode
const UnicodeString &input, // input decimal number
const UnicodeString &expected, // expected formatted result
UErrorCode &status) {
if (U_FAILURE(status)) {
return;
}
DecimalFormatSymbols symbols(Locale::getUS(), status);
// printf("Pattern = %s\n", UnicodeStringPiece(pattern).data());
DecimalFormat fmtr(pattern, symbols, status);
if (U_FAILURE(status)) {
errln("file dcfmtest.txt, line %d: %s error creating the formatter.",
lineNum, u_errorName(status));
return;
}
if (round=="ceiling") {
fmtr.setRoundingMode(DecimalFormat::kRoundCeiling);
} else if (round=="floor") {
fmtr.setRoundingMode(DecimalFormat::kRoundFloor);
} else if (round=="down") {
fmtr.setRoundingMode(DecimalFormat::kRoundDown);
} else if (round=="up") {
fmtr.setRoundingMode(DecimalFormat::kRoundUp);
} else if (round=="halfeven") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfEven);
} else if (round=="halfdown") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfDown);
} else if (round=="halfup") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfUp);
} else if (round=="default") {
// don't set any value.
} else {
fmtr.setRoundingMode(DecimalFormat::kRoundFloor);
errln("file dcfmtest.txt, line %d: Bad rounding mode \"%s\"",
lineNum, UnicodeStringPiece(round).data());
}
UnicodeString result;
UnicodeStringPiece spInput(input);
//fmtr.format(spInput, result, NULL, status);
Formattable fmtbl;
fmtbl.setDecimalNumber(spInput, status);
//NumberFormat &nfmtr = fmtr;
fmtr.format(fmtbl, result, NULL, status);
if (U_FAILURE(status)) {
errln("file dcfmtest.txt, line %d: format() returned %s.",
lineNum, u_errorName(status));
return;
}
if (result != expected) {
errln("file dcfmtest.txt, line %d: expected \"%s\", got \"%s\"",
lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data());
}
}
示例2: format
UnicodeString&
NumberFormat::format(const StringPiece &decimalNum,
UnicodeString& toAppendTo,
FieldPositionIterator* fpi,
UErrorCode& status) const
{
Formattable f;
f.setDecimalNumber(decimalNum, status);
format(f, toAppendTo, fpi, status);
return toAppendTo;
}
示例3: execFormatTest
void DecimalFormatTest::execFormatTest(int32_t lineNum,
const UnicodeString &pattern, // Pattern
const UnicodeString &round, // rounding mode
const UnicodeString &input, // input decimal number
const UnicodeString &expected, // expected formatted result
EFormatInputType inType, // input number type
UErrorCode &status) {
if (U_FAILURE(status)) {
return;
}
DecimalFormatSymbols symbols(Locale::getUS(), status);
// printf("Pattern = %s\n", UnicodeStringPiece(pattern).data());
DecimalFormat fmtr(pattern, symbols, status);
if (U_FAILURE(status)) {
dataerrln("file dcfmtest.txt, line %d: %s error creating the formatter.",
lineNum, u_errorName(status));
return;
}
if (round=="ceiling") {
fmtr.setRoundingMode(DecimalFormat::kRoundCeiling);
} else if (round=="floor") {
fmtr.setRoundingMode(DecimalFormat::kRoundFloor);
} else if (round=="down") {
fmtr.setRoundingMode(DecimalFormat::kRoundDown);
} else if (round=="up") {
fmtr.setRoundingMode(DecimalFormat::kRoundUp);
} else if (round=="halfeven") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfEven);
} else if (round=="halfdown") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfDown);
} else if (round=="halfup") {
fmtr.setRoundingMode(DecimalFormat::kRoundHalfUp);
} else if (round=="default") {
// don't set any value.
} else if (round=="unnecessary") {
fmtr.setRoundingMode(DecimalFormat::kRoundUnnecessary);
} else {
fmtr.setRoundingMode(DecimalFormat::kRoundFloor);
errln("file dcfmtest.txt, line %d: Bad rounding mode \"%s\"",
lineNum, UnicodeStringPiece(round).data());
}
const char *typeStr = "Unknown";
UnicodeString result;
UnicodeStringPiece spInput(input);
switch (inType) {
case kFormattable:
{
typeStr = "Formattable";
Formattable fmtbl;
fmtbl.setDecimalNumber(spInput, status);
fmtr.format(fmtbl, result, NULL, status);
}
break;
case kStringPiece:
typeStr = "StringPiece";
fmtr.format(spInput, result, NULL, status);
break;
}
if ((status == U_FORMAT_INEXACT_ERROR) && (result == "") && (expected == "Inexact")) {
// Test succeeded.
status = U_ZERO_ERROR;
return;
}
if (U_FAILURE(status)) {
errln("[%s] file dcfmtest.txt, line %d: format() returned %s.",
typeStr, lineNum, u_errorName(status));
status = U_ZERO_ERROR;
return;
}
if (result != expected) {
errln("[%s] file dcfmtest.txt, line %d: expected \"%s\", got \"%s\"",
typeStr, lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data());
}
}