June 06, 2012

Req: Is two decimal value in Given String.......



public class IsGivenNumberTwoDigits {

public static void main(String[] args) {
String s = "EMP_SAL=1003.00";//Scenario 2 :   1003.02220

String sTranDisbAmt = "EMP_SAL";
// 012345678
boolean s1 = s.contains(sTranDisbAmt);
if (s.startsWith(sTranDisbAmt)) {
String s4 = s.substring(8, s.length());
if (s4.length() == 0) {
System.out.println("Transaction distribution Amount is Empty.");
} else {
System.out.println("Transaction distribution Amount("
+ sTranDisbAmt + ") : " + s4);
boolean isDigitFlag = IsGivenNumberTwoDigits.is2DigitValue(s4);
if (isDigitFlag)
System.out.println("Transaction distribution Amount is two Digit value.");
else
System.out.println("Transaction distribution Amount is not two Digit value.");
}

}
}

public static boolean is2DigitValue(String s4) {
boolean isFlag = false;
if (s4.contains(".")) {
String[] s5 = s4.split("\\.");
for (String s6 : s5) {
if (s6.length() > 3) {
isFlag = false;
} else
isFlag = true;
}
}
return isFlag;
}
}


OutPut:
Scenario 1:

Transaction distribution Amount( EMP_SAL ) : 1003.00
Transaction distribution Amount is two Digit value.

Scenario 2:

Transaction distribution Amount( EMP_SAL ) : 1003.02220
Transaction distribution Amount is not two Digit value.




No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts