本文整理汇总了Java中org.javamoney.moneta.format.CurrencyStyle类的典型用法代码示例。如果您正苦于以下问题:Java CurrencyStyle类的具体用法?Java CurrencyStyle怎么用?Java CurrencyStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CurrencyStyle类属于org.javamoney.moneta.format包,在下文中一共展示了CurrencyStyle类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testWithCustomPattern
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Test related to {@link https://java.net/jira/browse/JAVAMONEY-92}.
*/
@Test
public void testWithCustomPattern() {
MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(
AmountFormatQueryBuilder.of(Locale.GERMANY)
.set(CurrencyStyle.SYMBOL)
.set("pattern", "#,##0.00### ¤")
.build());
Money money = Money.of(12345.23456789, "EUR");
assertEquals("12.345,23457 €", format.format(money));
format = MonetaryFormats.getAmountFormat(
AmountFormatQueryBuilder.of(Locale.GERMANY)
.set(CurrencyStyle.SYMBOL)
.build());
assertEquals("12.345,23 €", format.format(money));
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:22,代码来源:MonetaryAmountFormatTest.java
示例2: main
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
public static void main(String[] args) {
MonetaryAmount amount = Money.of(12345.67, "USD");
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(
AmountFormatQueryBuilder.of(Locale.US)
.set(CurrencyStyle.NAME)
.set("pattern", "00,00,00,00.00 ¤")
.build());
String formatted = customFormat.format(amount); //00,01,23,45.67 US Dollar
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:MonetaryFormatsExampleQueryCustom.java
示例3: CurrencyToken
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Creates a new {@link CurrencyToken}.
*
* @param style The style defining, how the currency should be localized, not
* {@code null}.
* @param locale The target locale, not {@code null}.
*/
public CurrencyToken(CurrencyStyle style, Locale locale) {
Objects.requireNonNull(locale, "Locale null");
this.locale = locale;
if (style!=null) {
this.style = style;
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:15,代码来源:CurrencyToken.java
示例4: initPattern
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
private void initPattern(String pattern, List<FormatToken> tokens,
AmountFormatContext style) {
int index = pattern.indexOf(CURRENCY_SIGN);
if (index > 0) { // currency placement after, between
String p1 = pattern.substring(0, index);
String p2 = pattern.substring(index + 1);
if (isLiteralPattern(p1)) {
tokens.add(new LiteralToken(p1));
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style.
get(Locale.class)));
} else {
tokens.add(new AmountNumberToken(style, p1));
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style.get(Locale.class)));
}
if (!p2.isEmpty()) {
if (isLiteralPattern(p2)) {
tokens.add(new LiteralToken(p2));
} else {
tokens.add(new AmountNumberToken(style, p2));
}
}
} else if (index == 0) { // currency placement before
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style
.get(Locale.class)));
tokens.add(new AmountNumberToken(style, pattern.substring(1)));
} else { // no currency
tokens.add(new AmountNumberToken(style, pattern));
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:30,代码来源:DefaultMonetaryAmountFormat.java
示例5: format
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
@Override
public String format(final MonetaryAmount monetaryAmount) {
final boolean isDecimal = monetaryAmount.getNumber().doubleValueExact() % 1 != 0;//TODO this can be improved with monetary query
final AmountFormatQuery pattern = AmountFormatQueryBuilder.of(locale)
.set(CurrencyStyle.SYMBOL)
.set(PATTERN, isDecimal ? PATTERN_WITH_DECIMAL : PATTERN_WITHOUT_DECIMAL)
.build();
return MonetaryFormats.getAmountFormat(pattern).format(monetaryAmount);
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:10,代码来源:PriceFormatterImpl.java
示例6: CurrencyToken
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Creates a new {@link CurrencyToken}.
*
* @param style The style defining, how the currency should be localized, not
* {@code null}.
* @param locale The target locale, not {@code null}.
*/
CurrencyToken(CurrencyStyle style, Locale locale) {
Objects.requireNonNull(locale, "Locale null");
this.locale = locale;
if (Objects.nonNull(style)) {
this.style = style;
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:15,代码来源:CurrencyToken.java
示例7: initPattern
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
private void initPattern(String pattern, List<FormatToken> tokens,
AmountFormatContext style) {
int index = pattern.indexOf(CURRENCY_SIGN);
if (index > 0) { // currency placement after, between
String p1 = pattern.substring(0, index);
String p2 = pattern.substring(index + 1);
if (isLiteralPattern(p1, style)) {
tokens.add(new LiteralToken(p1));
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style.
get(Locale.class)));
} else {
tokens.add(new AmountNumberToken(style, p1));
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style.get(Locale.class)));
}
if (!p2.isEmpty()) {
if (isLiteralPattern(p2, style)) {
tokens.add(new LiteralToken(p2));
} else {
tokens.add(new AmountNumberToken(style, p2));
}
}
} else if (index == 0) { // currency placement before
tokens.add(new CurrencyToken(style.get(CurrencyStyle.class), style
.get(Locale.class)));
tokens.add(new AmountNumberToken(style, pattern.substring(1)));
} else { // no currency
tokens.add(new AmountNumberToken(style, pattern));
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:30,代码来源:DefaultMonetaryAmountFormat.java
示例8: testFormatWithBuilder2
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Test method for
* {@link javax.money.format.MonetaryAmountFormat#format(javax.money.MonetaryAmount)} .
*/
@Test
public void testFormatWithBuilder2() {
MonetaryAmountFormat format = MonetaryFormats
.getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.NUMERIC_CODE).build());
assertEquals("12,50 756", format.format(
Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50).create()));
format = MonetaryFormats
.getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.SYMBOL).build());
assertEquals("$123,456.56", format.format(
Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(123456.561)
.create()));
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:MonetaryAmountFormatTest.java
示例9: main
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("USD");
MonetaryAmount money = Money.of(12, currency);
MonetaryAmountFormat format = MonetaryFormats
.getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.SYMBOL).build());
String resultText = format.format(money);//$12.00
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:MonetaryFormatsExampleQuery.java
示例10: setCurrencyStyle
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Explicitly configure the {@link CurrencyStyle} to be used.
*
* @param style the {@link CurrencyStyle}, not {@code null}.
* @return this token instance, for chaining.
*/
public CurrencyToken setCurrencyStyle(CurrencyStyle style) {
Objects.requireNonNull(style, "CurrencyStyle null");
this.style = style;
return this;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:CurrencyToken.java
示例11: getCurrencyStyle
import org.javamoney.moneta.format.CurrencyStyle; //导入依赖的package包/类
/**
* Access the {@link CurrencyStyle} used for formatting.
*
* @return the current {@link CurrencyStyle}, never {@code null}.
*/
public CurrencyStyle getCurrencyStyle() {
return this.style;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:CurrencyToken.java
注:本文中的org.javamoney.moneta.format.CurrencyStyle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论