By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

Determining which numeric value in a string is larger does not work.

P: 1
Trying to parse some Java code in a middleware tool but somehow determining which numeric value in a string is larger does not work.

The input variables are:
- TRDT and VLDT are strings and contain the date in format YYYYMMDD
- OWOVHE_R contains a string read from a file
- oOWOVHE contains the output value
- iOWOVHE contains the input value

The below JAVA code is called for every record read of a file and the purpose is to determine which value to take from the table (the valid date VLDT needs to be smaller or equal to the transaction date TRDT).

Expand|Select|Wrap|Line Numbers
  1. Integer nTRDT = Integer.parseInt(TRDT.trim());
  2. Integer nVLDT = Integer.parseInt(VLDT.trim());
  4. if (nTRDT >= nVLDT) 
  5. {oOWOVHE = OWOVHE_R;} 
  6. else 
  7. {oOWOVHE = iOWOVHE;}

gives this result:
TRDT=20130307; VLDT=20120101; OWOVHE_R=7.500000; OWOVHE=7.500000
TRDT=20130307; VLDT=20130101; OWOVHE_R=6.000000; OWOVHE=6.000000
TRDT=20130307; VLDT=20131201; OWOVHE_R=9.000000; OWOVHE=9.000000

For the last OWEVHE the value should remain 6 as TRDT is smaller then VLDT.

What is wrong in the comparison? Should I not make then Integers? But how can I compare strings in a larger then?
Mar 8 '13 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,421
There's not much we can help with if we don't know how and where oOWOVHE, OWOVHE_R, and iOWOVHE are defined.
Mar 8 '13 #2

P: 13,264
No, the problem is that you are reading a date as an integer. Convert the values to dates first using

Expand|Select|Wrap|Line Numbers
  1. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyMMdd");
  2. if(dateFormat.parse(TRDT.trim()).after(dateFormat.parse(VLDT.trim()))) {
  3.          // do your TRDT is greater logic here  
  4.         } 
Mar 8 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.