Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

UCCX Script Java Help

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

Try this:s = s.substring(0, s

Try this:

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

where s is strNumberEntered

that value is actually:s

that value is actually:

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

9 REPLIES

Try this:s = s.substring(0, s

Try this:

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

where s is strNumberEntered

New Member

That worked perfectly. Thank

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

that value is actually:

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

New Member

Thank you very much..So if i

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(

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

Substract..

New Member

That one worked for above..

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

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 )

New Member

Ok I will do my best and try.

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

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..

 

116
Views
0
Helpful
9
Replies
CreatePlease login to create content