jscience
  1. jscience
  2. JSCIENCE-112

100 EuroCents are not equal to one Euro

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      112

      Description

      When trying to use the lib for coping with currencies (especially EUR and
      EUR-cents), I cannot get this JUnit-test-case to get "green":

      public class TestCurrency {
      private static final Amount<Money> ONE_EURO = Amount.valueOf(1, Currency.EUR);
      private static Unit<Money> EURO_CENT = Currency.EUR.times(100);

      @Test
      public void test1()

      { Amount<Money> amount = Amount.valueOf(100, EURO_CENT); Currency.EUR.setExchangeRate(100); Amount<Money> amount2 = amount.to(Currency.EUR); Assert.assertEquals(ONE_EURO.getExactValue(), amount2.getExactValue()); }

      }

      I get the exception:

      org.jscience.physics.amount.AmountException: Inexact measures don't have
      exact values

      I understand this results from using a "double" for the exchange-rate.

      Is there any way to get a comparison "1 EUR = 100 EUR-Cents" to work?

        Activity

        Hide
        mbrinkma1 added a comment -

        Proposal: for coping with exchange-rates / VAT-calculations etc. it is a good
        choice to use java.lang.BigDecimal instead of float- or double-calculations.

        Show
        mbrinkma1 added a comment - Proposal: for coping with exchange-rates / VAT-calculations etc. it is a good choice to use java.lang.BigDecimal instead of float- or double-calculations.

          People

          • Assignee:
            jscience-issues
            Reporter:
            mbrinkma1
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: