简体   繁体   中英

Oracle ADF: Cannot convert 1 of type class java.math.BigDecimal to class oracle.jbo.domain.Number

This question look stupid but not realy. Cannot convert 1 of type class java.math.BigDecimal to class oracle.jbo.domain.Number

How to convert

  1. oracle.jbo.domain.Number into java.math.BigDecimal
  2. java.math.BigDecimal into oracle.jbo.domain.Number

I get the Answer number one:

 oracle.jbo.domain.Number value = (Number)valueChangeEvent.getNewValue();
 java.math.BigDecimal costOfBuildingValue = value.bigDecimalValue();

Number two?

You can use the String representation of the number in both ways:

oracle.jbo.domain.Number number = new oracle.jbo.domain.Number(12345);
BigDecimal bigDecimal = new BigDecimal(number.toString());

and vice-versa:

BigDecimal bigDecimal = new BigDecimal(1241241);
oracle.jbo.domain.Number number = new oracle.jbo.domain.Number(bigDecimal.toString());

Even better, if you checkout the javadoc, you will see that there's a Number(BigDecimal bigDecimal) constructor:

BigDecimal bigDecimal = new BigDecimal(1241241);
oracle.jbo.domain.Number number = new oracle.jbo.domain.Number(bigDecimal);

Note that I'm using the fully-qualified class name of oracle.jbo.domain.Number to avoid confusion with the java.lang.Number interface.

Create a new Number as follows:

BigDecimal value = new BigDecimal(...);
Number costOfBuildingNumber = new Number(value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM