08-07-2014 09:16 AM - edited 03-14-2019 01:44 PM
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
Solved! Go to Solution.
08-07-2014 09:41 AM
Try this:
s = s.substring(0, s.length()-2) + "." + s.substring(s.length()-2)
where s is strNumberEntered
08-07-2014 10:30 AM
08-07-2014 09:41 AM
Try this:
s = s.substring(0, s.length()-2) + "." + s.substring(s.length()-2)
where s is strNumberEntered
08-07-2014 10:17 AM
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
08-07-2014 10:30 AM
that value is actually:
s.substring(0, s.length()-2)
08-07-2014 12:57 PM
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)
08-07-2014 12:58 PM
s = s.substring( 0, s.length() - 2 )
Substract..
08-07-2014 01:02 PM
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"
08-07-2014 01:13 PM
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 )
08-07-2014 01:36 PM
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 $$)
08-07-2014 01:40 PM
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..
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: