本文整理汇总了Java中org.javamoney.moneta.FastMoney类的典型用法代码示例。如果您正苦于以下问题:Java FastMoney类的具体用法?Java FastMoney怎么用?Java FastMoney使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastMoney类属于org.javamoney.moneta包,在下文中一共展示了FastMoney类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: act
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
try {
long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
Product product = base.products().product(number);
JsonReader reader = Json.createReader(req.body());
JsonObject json = reader.readObject();
String name = json.getString("name");
String desc = json.getString("desc");
FastMoney price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");
Product result = product.update(name, desc, price);
return new RsJson(result);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:19,代码来源:TkProductUpdate.java
示例2: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, currency);
MonetaryOperator doubleOperator = m -> m.multiply(2);
MonetaryAmount result = doubleOperator.apply(money);//BRL 20.00000
MonetaryAmount result2 = result.with(doubleOperator);//BRL 40.00000
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:HelloMonetaryOperator.java
示例3: setupModule
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
final SimpleSerializers serializers = new SimpleSerializers();
serializers.addSerializer(CurrencyUnit.class, new CurrencyUnitSerializer());
serializers.addSerializer(MonetaryAmount.class, new MonetaryAmountSerializer(names, writer, formatFactory));
context.addSerializers(serializers);
final SimpleDeserializers deserializers = new SimpleDeserializers();
deserializers.addDeserializer(CurrencyUnit.class, new CurrencyUnitDeserializer());
deserializers.addDeserializer(MonetaryAmount.class, new MonetaryAmountDeserializer<>(amountFactory, names));
// for reading into concrete implementation types
deserializers.addDeserializer(Money.class, new MonetaryAmountDeserializer<>(moneyFactory, names));
deserializers.addDeserializer(FastMoney.class, new MonetaryAmountDeserializer<>(fastMoneyFactory, names));
deserializers.addDeserializer(RoundedMoney.class, new MonetaryAmountDeserializer<>(roundedMoneyFactory, names));
context.addDeserializers(deserializers);
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:17,代码来源:MoneyModule.java
示例4: otherOperations
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void otherOperations() {
CurrencyUnit euro = Monetary.getCurrency("EUR");
MonetaryAmount amount = FastMoney.of(150, euro);
FastMoney money = FastMoney.of(150, "EUR");
assertEquals(amount, money);
FastMoney third = money.divide(3);
assertEquals(third, FastMoney.of(50, euro));
MonetaryOperator tenPercent = MonetaryOperators.percent(10);
FastMoney tenPercentValue = money.with(tenPercent);
assertEquals(tenPercentValue, FastMoney.of(15, "EUR"));
// excellent comparison functions:
//money.isZero()
//MonetaryFunctions
Log.d("test", "the end, debug manually");
}
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:23,代码来源:JavaMoneyTests.java
示例5: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
MonetaryAmount amount = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
amount = Monetary.getAmountFactory(FastMoney.class).setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
amount = Monetary.getAmountFactory(
MonetaryAmountFactoryQueryBuilder.of().setMaxScale(50).setPrecision(30).build())
.setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
Money amt1 = Money.of(10.1234556123456789, "USD");
FastMoney amt2 = FastMoney.of(123456789, "USD");
Money total = amt1.add(amt2).multiply(0.5)
.remainder(1);
ConsoleUtils.printDetails(total);
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:23,代码来源:AmountsDoCalculations.java
示例6: setAmount
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public void setAmount(MonetaryAmount amount) {
if (amount != null) {
codeBox.getSelectionModel().select(
amount.getCurrency().getCurrencyCode());
if (FastMoney.class.equals(amount.getClass())) {
numberType.getSelectionModel().select("Long");
} else {
numberType.getSelectionModel().select("BigDecimal");
}
numberValue.setText(Money.from(amount).getNumber()
.toString());
} else {
codeBox.getSelectionModel().clearSelection();
numberType.getSelectionModel().clearSelection();
numberValue.setText("0");
}
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:18,代码来源:AmountEntry.java
示例7: act
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
try {
JsonReader reader = Json.createReader(req.body());
JsonObject json = reader.readObject();
String name = json.getString("name");
String desc = json.getString("desc");
MonetaryAmount price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");
Product result = base.products().add(name, desc, price);
return new RsJson(result);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:15,代码来源:TkProductAdd.java
示例8: create
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
private Product create(ResultSet rSet) throws SQLException {
return new ConstProduct(
new H2Product(dBase, rSet.getLong(1)),
rSet.getString(2),
rSet.getString(3),
FastMoney.of(rSet.getLong(4), "CZK"));
}
开发者ID:yaroska,项目名称:true_oop,代码行数:8,代码来源:ConstH2Products.java
示例9: price
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
private MonetaryAmount price() {
try {
return FastMoney.of(
new BigDecimal(
new JdbcSession(dBase)
.sql("SELECT price FROM product WHERE id=?")
.set(this.number)
.select(new SingleOutcome<>(String.class))),
"CZK");
} catch (SQLException e) {
return ExceptionUtils.rethrow(e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:14,代码来源:H2Product.java
示例10: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.TEN, currency);
MonetaryAmount money2 = FastMoney.of(BigDecimal.TEN, currency);
MonetaryAmount addResult = money.add(money2);//BRL 20 Money implementation
MonetaryAmount subtractResult = money2.subtract(addResult);//BRL -10 FastMoney implementation
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:ArithmeticOperations.java
示例11: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency(Locale.US);
MonetaryAmount money = Money.of(10, currency);
MonetaryAmount money2 = FastMoney.of(20, currency);
MonetaryAmount money3 = RoundedMoney.of(30, currency, MonetaryOperators.rounding());
String text = money.toString();//USD 10
String text2 = money2.toString();//USD 20
String text3 = money3.toString();//USD 30
MonetaryAmount result = Money.parse(text);
MonetaryAmount result2 = FastMoney.parse(text2);
MonetaryAmount result3 = RoundedMoney.parse(text3);
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:14,代码来源:ToStringExample.java
示例12: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, currency);
MonetaryQuery<String> currencyCodeQuery = m -> m.getCurrency().getCurrencyCode();
String result = currencyCodeQuery.queryFrom(money);//BRL
String result2 = money.query(currencyCodeQuery);//BRL
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:HelloMonetaryQuery.java
示例13: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
CurrencyConversion currencyConversion = provider.getCurrencyConversion(dollar);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:ExchangeRateProviderExample.java
示例14: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
MonetaryAmount result = money.add(money2);//javax.money.MonetaryException: Currency mismatch: USD/BRL
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:MistakeExample.java
示例15: data
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Parameters(name = "{0}, {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{FastMoney.of(29.95, "EUR"), FastMoney.of(100, "EUR"), FastMoney.of(0.0001, "EUR")},
{Money.of(29.95, "EUR"), Money.of(100, "EUR"), Money.of(0.0001, "EUR")},
{RoundedMoney.of(29.95, "EUR", getDefaultRounding()),
RoundedMoney.of(100, "EUR", getDefaultRounding()),
RoundedMoney.of(0.0001, "EUR", getDefaultRounding())},
});
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:11,代码来源:MonetaryAmountSerializerTest.java
示例16: createInstances
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void createInstances() {
// currency
CurrencyUnit euro = Monetary.getCurrency("EUR");
assertThat(euro.getCurrencyCode(), equalTo("EUR"));
CurrencyUnit aussie = Monetary.getCurrency("AUD");
//MonetaryAmount amount = 20;
Money money = Money.of(150, euro);
assertThat(money.getCurrency().getCurrencyCode(), equalTo("EUR"));
// Money division = money.divide(2.54);
// Log.d("test", division.toString());
FastMoney fast = FastMoney.of(250, euro);
assertThat(fast.getCurrency().getCurrencyCode(), equalTo("EUR"));
assertThat(fast.getNumber().toString(), equalTo("250.00000"));
assertThat(fast.getPrecision(), equalTo(2));
assertThat(fast.getScale(), equalTo(5));
// maximum size for fast money
// FastMoney maxFast = FastMoney.MAX_VALUE;
//MonetaryAmount unknown = new FastMoneyAmountBuilder().setNumber(30).create();
Log.d("test", "the end, debug manually");
}
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:30,代码来源:JavaMoneyTests.java
示例17: extremeValues
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void extremeValues() {
// todo: These values have XXX as currency. Use this when needing numbers only.
CurrencyUnit xxx = Monetary.getCurrency("XXX");
MonetaryAmount minimum = FastMoney.MIN_VALUE;
// assertThat(minimum, FastMoney.of(-92233720368547.75808, xxx)); <- overflow
assertEquals(minimum.toString(), "XXX -92233720368547.75808");
MonetaryAmount maximum = FastMoney.MAX_VALUE;
assertEquals(maximum.toString(), "XXX 92233720368547.75807");
MonetaryAmount zero = FastMoney.of(0, xxx);
assertThat(zero.isZero(), is(true));
MonetaryAmount random = FastMoney.of(358.46, xxx);
MonetaryAmount copy = FastMoney.from(random);
assertEquals(copy, random);
// change currency
MonetaryAmount euros = FastMoney.of(random.getNumber(), "EUR");
assertThat(euros.getNumber().doubleValueExact(), equalTo(random.getNumber().doubleValueExact()));
assertFalse(euros.getCurrency().equals(random.getCurrency()));
// comparison
assertTrue(random.isLessThan(maximum));
// can't compare different currencies
// assertThat(euros.isLessThan(maximum)).isTrue();
}
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:31,代码来源:JavaMoneyTests.java
示例18: testGetNumberType
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void testGetNumberType() throws Exception{
BigDecimal bd = new BigDecimal("0.1234523");
MonetaryAmount[] amounts = new MonetaryAmount[]{Money.of(bd, "USD"), FastMoney.of(2334434354L, "CHF")};
for(MonetaryAmount amount : amounts){
assertEquals("Invalid number type for " + amount, amount.getNumber().getNumberType(),
np.getNumberType(amount));
}
}
开发者ID:atsticks,项目名称:moneymachine,代码行数:10,代码来源:NumericRepresentationTest.java
示例19: testGetNumber
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void testGetNumber() throws Exception{
BigDecimal bd = new BigDecimal("0.1234523");
MonetaryAmount[] amounts = new MonetaryAmount[]{Money.of(bd, "USD"), FastMoney.of(2334434354L, "CHF")};
for(MonetaryAmount amount : amounts){
assertEquals("Invalid number type for " + amount, amount.getNumber().getNumberType(),
np.getNumberType(amount));
}
}
开发者ID:atsticks,项目名称:moneymachine,代码行数:10,代码来源:NumericRepresentationTest.java
示例20: testGetJDKNumber
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void testGetJDKNumber() throws Exception{
BigDecimal bd = new BigDecimal("0.1234523");
MonetaryAmount[] amounts = new MonetaryAmount[]{Money.of(bd, "USD"), FastMoney.of(2334434354L, "CHF")};
for(MonetaryAmount amount : amounts){
assertTrue("JDK Number can be more easily extracted for " + amount,
np.getNumber(amount) instanceof NumberValue);
assertEquals("Invalid JDK Number for " + amount, amount.getNumber(), np.getNumber(amount));
}
}
开发者ID:atsticks,项目名称:moneymachine,代码行数:11,代码来源:NumericRepresentationTest.java
注:本文中的org.javamoney.moneta.FastMoney类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论