Java Code Examples for org.javamoney.moneta.Money#parse()

The following examples show how to use org.javamoney.moneta.Money#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonetaryAmountAttributeConverter.java    From salespoint with Apache License 2.0 6 votes vote down vote up
@Override
public MonetaryAmount convertToEntityAttribute(String source) {

	if (source == null) {
		return null;
	}

	try {
		return Money.parse(source);
	} catch (RuntimeException e) {

		try {
			return Money.parse(source, FORMAT);
		} catch (RuntimeException inner) {

			// Propagate the original exception in case the fallback fails
			throw e;
		}
	}
}
 
Example 2
Source File: RoundingMonetaryAmountOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnNegativeValueUsingRoundingType() {
	operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN);
	CurrencyUnit currency = Monetary.getCurrency("BHD");
	MonetaryAmount money = Money.parse("BHD -1.34534432");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), -1.345);
}
 
Example 3
Source File: PercentOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnPositiveValue() {
	CurrencyUnit currency = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 200.0");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), 20.0);

}
 
Example 4
Source File: ExtractorMinorPartQueryTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnMajorPartPositive() {
	MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
	Long result = query.queryFrom(monetaryAmount);
	Long expected = 35L;
	assertEquals(result, expected);
}
 
Example 5
Source File: RoundingMonetaryAmountOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnPositiveValueUsingRoundingType() {
	operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN);
	CurrencyUnit currency = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 2.3523");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), 2.35);

}
 
Example 6
Source File: ExtractorMinorPartOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnPositiveValue() {
	CurrencyUnit currency = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 2.35");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), 0.35);

}
 
Example 7
Source File: ConvertMinorPartQueryTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnMajorPartNegative() {
	MonetaryAmount monetaryAmount = Money.parse("BHD -1.345");
	Long result = query.queryFrom(monetaryAmount);
	Long expected = -1345L;
	assertEquals(result, expected );
}
 
Example 8
Source File: ConvertMinorPartQueryTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnMajorPartPositive() {
	MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
	Long result = query.queryFrom(monetaryAmount);
	Long expected = 235L;
	assertEquals(result, expected );
}
 
Example 9
Source File: MonetaryOperatorsTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRoundingUsingScale() {
	CurrencyUnit euro = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 2.355432");
	MonetaryAmount result = MonetaryOperators.rounding(4).apply(money);
	assertNotNull(result);
	assertEquals(result.getCurrency(), euro);
	assertEquals(2.3554d, result.getNumber().doubleValue());
}
 
Example 10
Source File: MonetaryOperatorsTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRoundingUsingRoundingModeAndScale() {
	CurrencyUnit euro = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 2.355432");
	MonetaryAmount result = MonetaryOperators.rounding(RoundingMode.HALF_EVEN, 4).apply(money);
	assertNotNull(result);
	assertEquals(result.getCurrency(), euro);
	assertEquals(2.3554d, result.getNumber().doubleValue());
}
 
Example 11
Source File: ExchangeCurrencyOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnNegativeValue() {
	MonetaryAmount money = Money.parse("BHD -1.345");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), real);
	assertEquals(result.getNumber().doubleValue(), -1.345);

}
 
Example 12
Source File: ExtractorMajorPartQueryTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnMajorPartPositive() {
	MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
	Long result = query.queryFrom(monetaryAmount);
	Long expected = 2L;
	assertEquals(result, expected );
}
 
Example 13
Source File: ExchangeCurrencyOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnPositiveValue() {
	MonetaryAmount money = Money.parse("EUR 2.35");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), this.real);
	assertEquals(result.getNumber().doubleValue(), 2.35);
}
 
Example 14
Source File: PercentOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnNegativeValue() {
	CurrencyUnit currency = Monetary.getCurrency("BHD");
	MonetaryAmount money = Money.parse("BHD -200.0");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), -20.0);
}
 
Example 15
Source File: ReciprocalOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnNegativeValue() {
	CurrencyUnit currency = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR -2.0");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), -0.5);
}
 
Example 16
Source File: ReciprocalOperatorTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnPositiveValue() {
	CurrencyUnit currency = Monetary.getCurrency("EUR");
	MonetaryAmount money = Money.parse("EUR 2.0");
	MonetaryAmount result = operator.apply(money);
	assertEquals(result.getCurrency(), currency);
	assertEquals(result.getNumber().doubleValue(), 0.5);
}
 
Example 17
Source File: MonetaryQueriesTest.java    From jsr354-ri with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldExtractMinorPart(){
	MonetaryAmount money = Money.parse("EUR 2.35");
	Long result = money.query(MonetaryQueries.extractMinorPart());
	assertEquals(result, Long.valueOf(35L));
}
 
Example 18
Source File: MonetaryQueriesTest.java    From jsr354-ri with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldConvertMinorPart(){
	MonetaryAmount money = Money.parse("EUR 2.35");
	Long result = money.query(MonetaryQueries.convertMinorPart());
	assertEquals(result, Long.valueOf(235L));
}
 
Example 19
Source File: MonetaryFormatTable.java    From javamoney-examples with Apache License 2.0 4 votes vote down vote up
@Override
public MonetaryAmount parse(CharSequence text) throws MonetaryParseException {
	return Money.parse(text);
}
 
Example 20
Source File: MoneyModule.java    From cqrs-hotel with Apache License 2.0 4 votes vote down vote up
@Override
protected Money _deserialize(String value, DeserializationContext ctxt) throws IOException {
    return Money.parse(value);
}