We help IT Professionals succeed at work.

Integer to BigDecimal

jaggernat
jaggernat asked
on
9,360 Views
Last Modified: 2008-01-09
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

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)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
Or BigDecimal - whichever
Mick BarryJava 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());
}

Author

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

Author

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)
UNLOCK SOLUTION
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();

Author

Commented:
it could be anything , numbers or alphabets
Mick BarryJava 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

Author

Commented:
thanks
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)

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

Get Access
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

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

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

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
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

Ask ANY Question

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

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.