title: BigDecimal not keeping actual value when being returned from Java method
body: <p>I am making a Currency conversion app in Java. Some other awesome StackOverflowians gave me advice to read up on BigDecimal for the purpose of replacing double to fix any precision issues.</p>
  
  <p>I have a two method system; where it converts from the starting currency into USD, then converts the USD value to the destination currency.</p>
  
  <p>Note, my conversion rates are stored like this:</p>
  
  <pre><code>// Conversion Rates - START (as of October 30, 2018 @ 3:19 AM)
  // Rates obtained from exchange-rates.org
  
  //Convert to United States Dollar rates
  private final BigDecimal CAD_TO_USD = new BigDecimal(0.76135);
  private final BigDecimal EUR_TO_USD = new BigDecimal(1.1345);
  private final BigDecimal YEN_TO_USD = new BigDecimal(0.008853);
  // Conversion Rates - END
  </code></pre>
  
  <p>After I replaced my doubles with their respective BigDecimals - I decided to test it and see how it all works out.</p>
  
  <p>My tester class runs the following method to start the conversion process.</p>
  
  <pre><code>public BigDecimal convert()
  {
      BigDecimal value;
  
      value = convertToUSD(); //Converts the current currency into USD 
      value = convertFromUSD(value);  //Converts the previous USD currency value into the destination currency
  
      return value;
  }
  </code></pre>
  
  <p>When I enter my sample variables (which are converting 2.78 YEN to Canadian Dollars), I stepped through the process and found that everything functions up until I return a value.</p>
  
  <p>From the earlier mentioned method, <code>convertToUSD()</code> is run and is coded as follows</p>
  
  <pre><code>private BigDecimal convertToUSD()
  {
      switch (fromCurrency)
      {
          case "USD":
              return fromQuantity.multiply(new BigDecimal(1));
  
          case "CAD":
              return fromQuantity.multiply(CAD_TO_USD);
  
          case "EUR":
              return fromQuantity.multiply(EUR_TO_USD);
  
          case "YEN":
              return fromQuantity.multiply(YEN_TO_USD);
      }
  
      return new BigDecimal(0);
  }
  </code></pre>
  
  <p>ALl the values are passed in correctly, it steps through down to the proper case ("YEN"), and the variable pane shows that the "fromQuantity" BigDecimal has a intCompact value of 278 (which makes sense to me)</p>
  
  <p><a href="https://i.stack.imgur.com/YM7ca.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YM7ca.png" alt="enter image description here"></a></p>
  
  <p>As soon as the breakpoint returns back to the "convert" method, it gets all messed up. Instead of returning the <code>2.78 * 0.008853 = 0.0246</code>, it returns <code>-9223372036854775808</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/CZilA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CZilA.png" alt="enter image description here"></a></p>
  
  <p>This causes all other calculations to produce and error.</p>
  
  <p>I am new to using BigDecimal, so I may be making a complete obvious mistake; but I am happy to learn, so I sought advice from you guys :)</p>
  
  <p>Any assistance is appreciated.</p>