本文整理汇总了C++中NumberFormat类的典型用法代码示例。如果您正苦于以下问题:C++ NumberFormat类的具体用法?C++ NumberFormat怎么用?C++ NumberFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NumberFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToICU
bool
NumberValcon::parse(const QString& text)
{
if (text.isEmpty()) {
_value = 0;
return true;
}
UnicodeString utext = convertToICU(text);
// Parse the number using ICU
UErrorCode status = U_ZERO_ERROR;
NumberFormat* fmt = NumberFormat::createInstance(status);
if (U_SUCCESS(status)) {
Formattable value;
ParsePosition pos;
fmt->parse(utext, value, pos);
if (pos.getErrorIndex() == -1 && pos.getIndex() == utext.length()) {
#if U_ICU_VERSION_MAJOR_NUM < 3
_value = value.getDouble(&status);
#else
_value = value.getDouble(status);
#endif
return true;
}
}
return false;
}
示例2: fmt
void RelativeDateTimeFormatterTest::TestCustomNumberFormat() {
NumberFormat *nf;
UErrorCode status = U_ZERO_ERROR;
{
RelativeDateTimeFormatter fmt("en", status);
if (U_FAILURE(status)) {
dataerrln(
"Failure creating format object - %s", u_errorName(status));
return;
}
nf = (NumberFormat *) fmt.getNumberFormat().clone();
}
nf->setMinimumFractionDigits(1);
nf->setMaximumFractionDigits(1);
RelativeDateTimeFormatter fmt("en", nf, status);
// Test copy constructor.
RelativeDateTimeFormatter fmt2(fmt);
RunTest(fmt2, kEnglishDecimal, UPRV_LENGTHOF(kEnglishDecimal), "en decimal digits");
// Test assignment
fmt = RelativeDateTimeFormatter("es", status);
RunTest(fmt, kSpanishNoQuantity, UPRV_LENGTHOF(kSpanishNoQuantity), "assignment operator");
}
示例3:
/**
* Convenience method that ought to be in NumberFormat
*/
NumberFormat*
MessageFormat::createIntegerFormat(const Locale& locale, UErrorCode& status) const {
NumberFormat *temp = NumberFormat::createInstance(locale, status);
if (temp != NULL && temp->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
DecimalFormat *temp2 = (DecimalFormat*) temp;
temp2->setMaximumFractionDigits(0);
temp2->setDecimalSeparatorAlwaysShown(FALSE);
temp2->setParseIntegerOnly(TRUE);
}
return temp;
}
示例4: convertToQt
QString
NumberValcon::format()
{
// Format decimal using ICU default numeric format
UnicodeString text;
UErrorCode status = U_ZERO_ERROR;
NumberFormat* fmt = NumberFormat::createInstance(status);
fmt->format(_value.toDouble(), text, status);
if (U_FAILURE(status))
return "";
return convertToQt(text);
}
示例5: sink
std::string L10n::FormatDecimalNumberIntoString(double number) const
{
UErrorCode success = U_ZERO_ERROR;
UnicodeString utf16Number;
NumberFormat* numberFormatter = NumberFormat::createInstance(currentLocale, UNUM_DECIMAL, success);
numberFormatter->format(number, utf16Number);
char utf8Number[512];
CheckedArrayByteSink sink(utf8Number, ARRAY_SIZE(utf8Number));
utf16Number.toUTF8(sink);
ENSURE(!sink.Overflowed());
return std::string(utf8Number, sink.NumberOfBytesWritten());
}
示例6: convertToQt
QString
PercentValcon::format()
{
// Format money using ICU default percent format
UnicodeString text;
UErrorCode status = U_ZERO_ERROR;
NumberFormat* fmt = NumberFormat::createPercentInstance(status);
fmt->setMaximumFractionDigits(4);
fmt->format(_value.toDouble() / 100.0, text, status);
if (U_FAILURE(status))
return "";
return convertToQt(text);
}
示例7: unitsBundle
template<> U_I18N_API
const MeasureFormatCacheData *LocaleCacheKey<MeasureFormatCacheData>::createObject(
const void * /*unused*/, UErrorCode &status) const {
const char *localeId = fLoc.getName();
LocalUResourceBundlePointer unitsBundle(ures_open(U_ICUDATA_UNIT, localeId, &status));
static UNumberFormatStyle currencyStyles[] = {
UNUM_CURRENCY_PLURAL, UNUM_CURRENCY_ISO, UNUM_CURRENCY};
LocalPointer<MeasureFormatCacheData> result(new MeasureFormatCacheData(), status);
if (U_FAILURE(status)) {
return NULL;
}
if (!loadMeasureUnitData(
unitsBundle.getAlias(),
*result,
status)) {
return NULL;
}
result->adoptNumericDateFormatters(loadNumericDateFormatters(
unitsBundle.getAlias(), status));
if (U_FAILURE(status)) {
return NULL;
}
for (int32_t i = 0; i < WIDTH_INDEX_COUNT; ++i) {
// NumberFormat::createInstance can erase warning codes from status, so pass it
// a separate status instance
UErrorCode localStatus = U_ZERO_ERROR;
result->adoptCurrencyFormat(i, NumberFormat::createInstance(
localeId, currencyStyles[i], localStatus));
if (localStatus != U_ZERO_ERROR) {
status = localStatus;
}
if (U_FAILURE(status)) {
return NULL;
}
}
NumberFormat *inf = NumberFormat::createInstance(
localeId, UNUM_DECIMAL, status);
if (U_FAILURE(status)) {
return NULL;
}
inf->setMaximumFractionDigits(0);
DecimalFormat *decfmt = dynamic_cast<DecimalFormat *>(inf);
if (decfmt != NULL) {
decfmt->setRoundingMode(DecimalFormat::kRoundDown);
}
result->adoptIntegerFormat(inf);
result->addRef();
return result.orphan();
}
示例8: showCurrencyFormatting
static void
showCurrencyFormatting(UBool useICU26API) {
NumberFormat *nf;
int32_t i, j;
UnicodeString output;
UErrorCode errorCode;
// TODO: Using printf() here assumes that the runtime encoding is ASCII-friendly
// and can therefore be mixed with UTF-8
for(i=0; i<UPRV_LENGTHOF(sampleLocaleIDs); ++i) {
printf("show currency formatting (method for %s) in the locale \"%s\"\n",
useICU26API ? "ICU 2.6" : "before ICU 2.6",
sampleLocaleIDs[i]);
// get a currency formatter for this locale ID
errorCode=U_ZERO_ERROR;
nf=NumberFormat::createCurrencyInstance(sampleLocaleIDs[i], errorCode);
if(U_FAILURE(errorCode)) {
printf("NumberFormat::createCurrencyInstance(%s) failed - %s\n",
sampleLocaleIDs[i], u_errorName(errorCode));
continue;
}
for(j=0; j<UPRV_LENGTHOF(sampleCurrencies); ++j) {
printf(" - format currency \"%s\": ", sampleCurrencies[j]);
// set the actual currency to be formatted
if(useICU26API) {
setNumberFormatCurrency_2_6(*nf, sampleCurrencies[j], errorCode);
} else {
setNumberFormatCurrency_2_4(*nf, sampleCurrencies[j], errorCode);
}
if(U_FAILURE(errorCode)) {
printf("setNumberFormatCurrency(%s) failed - %s\n",
sampleCurrencies[j], u_errorName(errorCode));
continue;
}
// output=formatted currency value
output.remove();
nf->format(12345678.93, output);
output+=(UChar)0x0a; // '\n'
uprintf(output);
}
}
}
示例9: elLoc
// Test bug9042
void TimeUnitTest::testGreekWithSanitization() {
UErrorCode status = U_ZERO_ERROR;
Locale elLoc("el");
NumberFormat* numberFmt = NumberFormat::createInstance(Locale("el"), status);
if (!assertSuccess("NumberFormat::createInstance for el locale", status, TRUE)) return;
numberFmt->setMaximumFractionDigits(1);
TimeUnitFormat* timeUnitFormat = new TimeUnitFormat(elLoc, status);
if (!assertSuccess("TimeUnitFormat::TimeUnitFormat for el locale", status)) return;
timeUnitFormat->setNumberFormat(*numberFmt, status);
delete numberFmt;
delete timeUnitFormat;
}
示例10: createFormat
virtual NumberFormat* createFormat(const Locale& /* loc */, UNumberFormatStyle formatType)
{
if (formatType == UNUM_CURRENCY) {
return (NumberFormat*)currencyStyle->clone();
}
return NULL;
}
示例11: selectPlural
StandardPlural::Form QuantityFormatter::selectPlural(
const Formattable &number,
const NumberFormat &fmt,
const PluralRules &rules,
UnicodeString &formattedNumber,
FieldPosition &pos,
UErrorCode &status) {
if (U_FAILURE(status)) {
return StandardPlural::OTHER;
}
UnicodeString pluralKeyword;
const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(&fmt);
if (decFmt != NULL) {
number::impl::DecimalQuantity dq;
decFmt->formatToDecimalQuantity(number, dq, status);
if (U_FAILURE(status)) {
return StandardPlural::OTHER;
}
pluralKeyword = rules.select(dq);
decFmt->format(number, formattedNumber, pos, status);
} else {
if (number.getType() == Formattable::kDouble) {
pluralKeyword = rules.select(number.getDouble());
} else if (number.getType() == Formattable::kLong) {
pluralKeyword = rules.select(number.getLong());
} else if (number.getType() == Formattable::kInt64) {
pluralKeyword = rules.select((double) number.getInt64());
} else {
status = U_ILLEGAL_ARGUMENT_ERROR;
return StandardPlural::OTHER;
}
fmt.format(number, formattedNumber, pos, status);
}
return StandardPlural::orOtherFromString(pluralKeyword);
}
示例12: adoptNumberFormat
void
TimeUnitFormat::setNumberFormat(const NumberFormat& format, UErrorCode& status){
if (U_FAILURE(status)) {
return;
}
adoptNumberFormat((NumberFormat *)format.clone(), status);
}
示例13: stringBool
// Write AxisBlock keywords
bool UChromaSession::writeAxisBlock(LineParser& parser, Axes& axes, int axis)
{
parser.writeLineF(" %s %i\n", UChromaSession::viewPaneKeyword(UChromaSession::AxisBlockKeyword), axis);
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::AutoScaleKeyword), Axes::autoScaleMethod(axes.autoScale(axis)));
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::AutoTicksKeyword), stringBool(axes.autoTicks(axis)));
parser.writeLineF(" %s %f\n", UChromaSession::axisKeyword(UChromaSession::FirstTickKeyword), axes.tickFirst(axis));
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::FractionalPositioningKeyword), stringBool(axes.positionIsFractional(axis)));
parser.writeLineF(" %s %s %s %s\n", UChromaSession::axisKeyword(UChromaSession::GridLinesKeyword), stringBool(axes.gridLinesMajor(axis)), stringBool(axes.gridLinesMinor(axis)), stringBool(axes.gridLinesFull(axis)));
LineStyle style = axes.gridLineMajorStyle(axis);
parser.writeLineF(" %s %f '%s' %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::GridLineMajorStyleKeyword), style.width(), LineStipple::stipple[style.stipple()].name, style.colour().redF(), style.colour().greenF(), style.colour().blueF(), style.colour().alphaF());
style = axes.gridLineMinorStyle(axis);
parser.writeLineF(" %s %f '%s' %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::GridLineMinorStyleKeyword), style.width(), LineStipple::stipple[style.stipple()].name, style.colour().redF(), style.colour().greenF(), style.colour().blueF(), style.colour().alphaF());
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::InvertKeyword), stringBool(axes.inverted(axis)));
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::LabelAnchorKeyword), TextPrimitive::textAnchor(axes.labelAnchor(axis)));
parser.writeLineF(" %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::LabelOrientationKeyword), axes.labelOrientation(axis).x, axes.labelOrientation(axis).y, axes.labelOrientation(axis).z);
parser.writeLineF(" %s %f %f\n", UChromaSession::axisKeyword(UChromaSession::LimitsKeyword), axes.min(axis), axes.max(axis));
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::LogarithmicKeyword), stringBool(axes.logarithmic(axis)));
parser.writeLineF(" %s %i\n", UChromaSession::axisKeyword(UChromaSession::MinorTicksKeyword), axes.minorTicks(axis));
NumberFormat fmt = axes.numberFormat(axis);
parser.writeLineF(" %s '%s' %i %s %s\n", UChromaSession::axisKeyword(UChromaSession::NumberFormatKeyword), NumberFormat::formatType(fmt.type()), fmt.nDecimals(), stringBool(fmt.useUpperCaseExponent()), stringBool(fmt.forcePrecedingPlus()));
parser.writeLineF(" %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::PositionFractionalKeyword), axes.positionFractional(axis).x, axes.positionFractional(axis).y, axes.positionFractional(axis).z);
parser.writeLineF(" %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::PositionRealKeyword), axes.positionReal(axis).x, axes.positionReal(axis).y, axes.positionReal(axis).z);
parser.writeLineF(" %s %f\n", UChromaSession::axisKeyword(UChromaSession::StretchKeyword), axes.stretch(axis));
parser.writeLineF(" %s %f\n", UChromaSession::axisKeyword(UChromaSession::TickDeltaKeyword), axes.tickDelta(axis));
parser.writeLineF(" %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::TickDirectionKeyword), axes.tickDirection(axis).x, axes.tickDirection(axis).y, axes.tickDirection(axis).z);
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::TitleAnchorKeyword), TextPrimitive::textAnchor(axes.titleAnchor(axis)));
parser.writeLine(QString(" ")+UChromaSession::axisKeyword(UChromaSession::TitleKeyword)+" '"+axes.title(axis)+"'\n");
parser.writeLineF(" %s %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::TitleOrientationKeyword), axes.titleOrientation(axis).x, axes.titleOrientation(axis).y, axes.titleOrientation(axis).z, axes.titleOrientation(axis).w);
parser.writeLineF(" %s %s\n", UChromaSession::axisKeyword(UChromaSession::VisibleAxisKeyword), stringBool(axes.visible(axis)));
parser.writeLineF(" %s\n", UChromaSession::axisKeyword(UChromaSession::EndAxisKeyword));
return true;
}
示例14: stringConverter
void
BCountry::FormatNumber(BString* string, int32 value)
{
UErrorCode err;
NumberFormat* numberFormatter
= NumberFormat::createInstance(*fICULocale, err);
assert(err == U_ZERO_ERROR);
UnicodeString ICUString;
ICUString = numberFormatter->format((int32_t)value, ICUString);
string->Truncate(0);
BStringByteSink stringConverter(string);
ICUString.toUTF8(stringConverter);
}
示例15: adoptNumberFormat
void
DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)
{
NumberFormat* newNumFmtClone = (NumberFormat*)newNumberFormat.clone();
if (newNumFmtClone != NULL) {
adoptNumberFormat(newNumFmtClone);
}
}