jaggernat
asked on
Integer to BigDecimal
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]).toUppe rCase();
}
}
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.getPe ak()))) //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
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]).toUppe
}
}
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
}
//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
The getValues you've shown returns an array, so how can it be 1000?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or BigDecimal - whichever
this.values[i] = new BigInteger((String)values[ i]);
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].toStr ing());
}
if (values[i] !=null && values[i] instanceof String) {
// whatever
}
else if (values[i] !=null && values[i] instanceof Number) {
BigDecimal bi = new BigDecimal(values[i].toStr
}
ASKER
is this correct
(!BigInteger((String)value s[i]).equa ls(pricePl an.getPeak AllowanceM inutes()))
it shows an error:
It says method BigInteger is undefined for Type Plan class
(!BigInteger((String)value
it shows an error:
It says method BigInteger is undefined for Type Plan class
ASKER
my if statement is
if(!BigInteger((String)val ues[i]).eq uals(price Plan.getPe akAllowanc eMinutes() ))
if(!BigInteger((String)val
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the String types in the array contain numbers, why are you converting to uppercase?:
>>this.values[i] = ((String)values[i]).toUppe rCase();
>>this.values[i] = ((String)values[i]).toUppe
ASKER
it could be anything , numbers or alphabets
> 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
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
ASKER
thanks
:-)