2

this piece of code throw me: Cannot format given Object as a Number

  private BigDecimal notional;

 public String getNotional() {
    System.out.println("notional:" + notional);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.'); 
    System.out.println("notional:" + notional);
    String format = df.format(notional);
    System.out.println("notional2:" + format);


    if(notional!=null)
    notional = new BigDecimal(df.format(notional));
    return notional.toString();
 }

why?

   javax.el.ELException: /pages/emir/acknowledgedTransactions.xhtml @484,160 value="#{ackTxContractBean.firstleg.notional}":
    java.lang.IllegalArgumentException: Cannot format given Object as a Number

notional: 2279713.86 notional2: 2.279.713,86

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
FrankTan
  • 1,626
  • 6
  • 28
  • 63

1 Answers1

2

Probably because you are passing the format instead of the string maybe.

BigDecimal constructor you are targeting takes a String (BigDecimal(String )) None of the DecimalFormat.format methods seem to take a String. Just create your BigDeciamal and then format if afterward. What type is notional anyway.

Found this thread which seems to do what you want.

Community
  • 1
  • 1
onesixtyfourth
  • 744
  • 9
  • 30