We help IT Professionals succeed at work.

# Integer to BigDecimal

on
9,360 Views
hi guys
i have something like this in my value object CriteriaVO

private Object values[] = null;
public Object[] getValues() {
return values;
}

public void setValues(Object[] values) {
this.values = values;

for (int i=0; values!=null && i<values.length; i++){
if (values[i] !=null && values[i] instanceof String)
this.values[i] = ((String)values[i]).toUpperCase();
}

}

AND i have a method like this which uses the value object:

private static Search  modify(CriteriaVO criteria[] )
for (int j = 0; j < criteria.length; j++)
{
if((!criteria[j].getValues().equals(Plan.getPeak())))       //this is not matching
}

//criteria[j].getValues()  is 1000
and Plan.getPeak()  is of type Big integer and its value is 1000.00

so i want to convert criteria[j].getValues() (which is 1000)  to Bigdecimal so that the values match.

any idea how i can do that
thanks
J
Comment
Watch Question

## View Solutions Only

CERTIFIED EXPERT
Top Expert 2016

Commented:
The getValues you've shown returns an array, so how can it be 1000?
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
CERTIFIED EXPERT
Top Expert 2016

Commented:
Or BigDecimal - whichever
Java Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
this.values[i] = new BigInteger((String)values[i]);
CERTIFIED EXPERT
Top Expert 2016

Commented:
Assuming when an Object is String it's not a number (else why convert it to uppercase)

if (values[i] !=null && values[i] instanceof String) {
// whatever
}
else if (values[i] !=null && values[i] instanceof Number) {
BigDecimal bi = new BigDecimal(values[i].toString());
}

Commented:
is this correct
(!BigInteger((String)values[i]).equals(pricePlan.getPeakAllowanceMinutes()))

it shows an error:
It says method BigInteger is undefined for Type Plan class

Commented:
my if statement is
if(!BigInteger((String)values[i]).equals(pricePlan.getPeakAllowanceMinutes()))
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
CERTIFIED EXPERT
Top Expert 2016

Commented:
If the String types in the array contain numbers, why are you converting to uppercase?:

>>this.values[i] = ((String)values[i]).toUpperCase();

Commented:
it could be anything , numbers or alphabets
Java Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> it could be anything , numbers or alphabets

then you'll need to add a try/catch block around what i suggested above to habdle cases where it is not a number (unless you have some other way of telling)
Or first check if it numberic or not?

you can do that with a regular expression

http://www.objects.com.au/java/qa/1260329489.html

or loop thru the chars checking the digits (preferred)

let me know if u have any questions

Commented:
thanks
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Connect with Certified Experts to gain insight and support on specific technology challenges including:

• Troubleshooting
• Research
• Professional Opinions
Unlock the solution to this question.