当前位置: 首页>>代码示例>>Java>>正文


Java FastMoney.of方法代码示例

本文整理汇总了Java中org.javamoney.moneta.FastMoney.of方法的典型用法代码示例。如果您正苦于以下问题:Java FastMoney.of方法的具体用法?Java FastMoney.of怎么用?Java FastMoney.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.javamoney.moneta.FastMoney的用法示例。


在下文中一共展示了FastMoney.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的org.javamoney.moneta.FastMoney.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。