cancel
Showing results for
Did you mean:
cancel
1936
Views
5
3
Replies

## Value comparison in UCCX 7 script

Level 7

I'm trying to put a piece of logic into a script that compares a customer entered value (string variable) against a static value (100000000).  The logic I have looks like this:

If (valueEntered > "10000000") then

However almost any value entered returns a True result.  So if I entered in 115, the script is seeing 115 as larger than 10000000 even though it is not.

I've tried to change the variable to an integer variable from string, but no luck.  Anybody have any ideas on how to make this work so that only those values that are truely greater than 10000000 return a True result?

2 Accepted Solutions

Accepted Solutions
Level 4

You are comparing against a string ("10000000" is a string). Try:

if (valueEntered > 10000000)

or

if (Integer.parseInt(valueEntered) > 10000000)

Tanner Ezell www.ctilogic.com
VIP Alumni

Hi,

no, you cannot compare apples to oranges, Strings to Integers.

You can, however, cast a String into Integer. It's easy.

Integer.parseInt(stringValue)

If (Integer.parseInt(valueEntered) > 100000000)

etc.

http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#parseInt%28java.lang.String%29

G.

P.S. Integer is fine up to 2,147,483,647; for higher numbers use Long ~ (Long.parseLong(valueEntered)).

3 Replies 3
Level 4

You are comparing against a string ("10000000" is a string). Try:

if (valueEntered > 10000000)

or

if (Integer.parseInt(valueEntered) > 10000000)

Tanner Ezell www.ctilogic.com
VIP Alumni

Hi,

no, you cannot compare apples to oranges, Strings to Integers.

You can, however, cast a String into Integer. It's easy.

Integer.parseInt(stringValue)

If (Integer.parseInt(valueEntered) > 100000000)

etc.

http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#parseInt%28java.lang.String%29

G.

P.S. Integer is fine up to 2,147,483,647; for higher numbers use Long ~ (Long.parseLong(valueEntered)).

Thank you both!!  I had to change it to int.parseInt but that works perfectly and is returning an accurate response.