cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
914
Views
0
Helpful
9
Replies

UCCX Script Java Help

shurt
Level 1
Level 1

I need to add a " . " to a script variable. I know this can be done with substrings but the number of characters will always be different. But i need to add teh decimal in the 2nd position from the left no matter what. It is for an IVR app where user enters dollar amount. But need to add the decimal before i can treat rest of call. HOw can i do this?

 

i.e. - strNumberEntered = "1234567"

I need it to  be = strNumber = "12345.67"

 

THanks

Steve

2 Accepted Solutions

Accepted Solutions

Samuel Womack
Level 5
Level 5

Try this:

s = s.substring(0, s.length()-2) + "." + s.substring(s.length()-2)

where s is strNumberEntered

View solution in original post

that value is actually:

s.substring(0, s.length()-2)

View solution in original post

9 Replies 9

Samuel Womack
Level 5
Level 5

Try this:

s = s.substring(0, s.length()-2) + "." + s.substring(s.length()-2)

where s is strNumberEntered

That worked perfectly. Thank you for your help....

 

IF i needed to almost do the opposite. And only take characters to the left of a decimal so i can put into an integer. What syntax would be used?

 

i.e. str = "12345.75"

ends up being str2 = "12345"

?

Thank You so much

Steve

that value is actually:

s.substring(0, s.length()-2)

Thank you very much..

So if i wanted to keep just the two characters from the right is it the inverse of that? So it would delete everything including the decimal and to the left?

I tried below but that did not work!!

s.substring(0, s.length()2)

 


 

s = s.substring( 0, s.length() - 2 )

Substract..

That one worked for above.. What if i need to retain the two right digits?

thanks again for your help

i.e. - strNumberEntered = "12345.67"

I need it to  be = strNumber = "67"

That's the Last String in the original Concatenation:

s.substring( s.length() - 2 )

Hopefully the below doesn't go over the deep end..but:

Ultimately if you are trying to convert the Entire thing into a Number (integers don't do decimals/precison) then use Double (if you are going to do Math with Currency Double and Float aren't recommended..so Use BigDecimal):

double d = Double.parseDouble( s )

java.math.BigDecimal bd = new java.math.BigDecimal( s )

Ok I will do my best and try...

 

I know integer can't have decimal so that is why i was breaking up. One side is dollars the other side is cents. This way i can treat accordingly and present generated prompts for currency. Generated prompts for currency can only be derived from integer.. So the 2nd answer you gave me helped get everything from left of decimal point (the dollars) now i just need to pull out the two characters to the right (the cents). Thank you

 

So if i had str = "121345.67"

 

i want to set str2 = "67"

 

knowing that the number of characters to left of decimal can be different ever session.. (it is IVR user enters $$)

Honestly you don't really need the Create Generated Prompt Step to generate a "Recorded Currency" but it's probably best for you to do it the way you know how, however..you could just do the following:

Prompt pCurrency = $[ s ]

Where s is the String I created from before or if you converted to Double

p = $[ d ]

Refer to Volume 3 of the Expression Language Guide..

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: