• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9132
  • Last Modified:

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]).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
0
jaggernat
Asked:
jaggernat
  • 6
  • 4
  • 3
2 Solutions
 
CEHJCommented:
The getValues you've shown returns an array, so how can it be 1000?
0
 
CEHJCommented:
Anyhow

BigInteger bi = BigInteger.valueOf(i); // where 'i' is an int will get you the correct type
0
 
CEHJCommented:
Or BigDecimal - whichever
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
objectsCommented:
                       this.values[i] = new BigInteger((String)values[i]);
0
 
CEHJCommented:
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());
}
0
 
jaggernatAuthor 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
0
 
jaggernatAuthor Commented:
my if statement is
if(!BigInteger((String)values[i]).equals(pricePlan.getPeakAllowanceMinutes()))
0
 
objectsCommented:
> (!BigInteger((String)values[i]).equals(pricePlan.getPeakAllowanceMinutes()))

should be:

(!new BigInteger((String)values[i]).equals(pricePlan.getPeakAllowanceMinutes()))

or:

(!values[i].toString().equals(pricePlan.getPeakAllowanceMinutes().toString()))

or:

make it initially a BigInteger as I suggested earlier
 
0
 
CEHJCommented:
If the String types in the array contain numbers, why are you converting to uppercase?:

>>this.values[i] = ((String)values[i]).toUpperCase();
0
 
jaggernatAuthor Commented:
it could be anything , numbers or alphabets
0
 
objectsCommented:
> 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
0
 
jaggernatAuthor Commented:
thanks
0
 
CEHJCommented:
:-)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now