Search code examples
javastringobjectbigdecimalstring.format

ArgumentType: 'Big Decimal' does not match the type of the format specified '%d'


String stockStr = " ";

for (StockRecordDTO stockNumber : stockID)
{
    stockStr+= 

    String.format("the stock %s for Date %s with Quantity %d ", 
            stockNumber.getStock(),
            stockNumber.getBusinessDate(), 
            stockNumber.getQuantity()
        );
}

I am trying to print out an ArrayList of values by extracting it to a string and then printing it this way. I am getting the Values from a DTO class, and I'm getting an error with the string.format method I have used saying

ArgumentType: 'Big Decimal' does not match the type of the format specified '%d'

Quantity is defined as a BIG Decimal in DTO class.

So how do I solve this?

Thanks for helping in advance


Solution

  • You could try to convert the BigDeciaml to a double:

    stockNumber.getQuantity().doubleValue()
    

    Be careful with that, there might be a reason to use BigDeciamal in you class and converting it to a different type might lead to loss of precision.