0

In my application, if I input a number into 'invoiceAmount' say '1234.5' The app works fine and is able to handle this. If I try say '1234.55' I receive an error. (Sadly the error message is unhelpful to provide here).

To try and get around this, I have added the 'BigDecimal' section into this segment of code:

@RequestMapping(value="makeRetainedInvoicePlacement", method = {RequestMethod.POST, RequestMethod.GET})
public void makeRetainedInvoicePalcement(HttpServletRequest req, HttpServletResponse resp, Model model) throws IOException {
    String jobOrderID = req.getParameter("jobOrderID");
    String dateFormat = req.getParameter("dateFormat");
    String invoiceDateStr = req.getParameter("invoiceDate");
    String invoiceAmountDec = req.getParameter("invoiceAmount");
    String retainerStageInfo = req.getParameter("retainerStageInfo");

    Date invoiceDate = Utility.parseStringToDate(invoiceDateStr, dateFormat);
    BigDecimal invoiceAmount = Utility.parseBigDecimal(invoiceAmountDec);

    Integer placementID = jobService.saveInvoicePlacement(jobOrderID, invoiceAmount, retainerStageInfo, invoiceDate);

Whenever I try to build my app, I am met with: java.math.BigDecimal cannot be converted to java.lang.String

Basically my app creates a placement elsewhere and sets it into a custom field:

placement.setCustomBillRate5(Utility.parseBigDecimal(invoiceAmount));

I hope someone can help.

Brett
  • 43
  • 2
  • 10
  • 1
    You first call `Utility.parseBigDecimal(invoiceAmountDec);` (which I assume it works and accepts a `String` parameter), then you call `Utility.parseBigDecimal(invoiceAmount)` - This time you pass `invoiceAmount` which is a `BigDecimal`, while the method requires a `String`. Likely you meant `placement.setCustomBillRate5(invoiceAmount);` – BackSlash Nov 23 '17 at 12:25
  • Did you used `BigDecimal.toPlainString()` method? See [here](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#toPlainString()) for docs. – cse Nov 23 '17 at 12:27
  • Take a look at [this](https://stackoverflow.com/questions/13900204/bigdecimal-to-string) too – Joachim Huet Nov 23 '17 at 12:30
  • @BackSlash when I take your advice, I get the following two errors when building: SimpleJobService.java:[59,46] incompatible types: java.lang.String cannot be converted to java.math.BigDecimal (this is where I updated to placement.setCustomBillRate5(invoiceAmount); AND: RetainedInvoiceController.java:[85,83] incompatible types: java.math.BigDecimal cannot be converted to java.lang.String still – Brett Nov 24 '17 at 12:37

0 Answers0