cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1401
Views
15
Helpful
5
Replies

Call Studio - Convert Number to String

Gerry O'Rourke
Spotlight
Spotlight

Using the Set Value element I set the below.

But even when I tried the toString() the value of the local variable is a float (in this example) I add 20 + 7 and get 27.0

 

I need to get the value "27" - and not "27.0" - any ideas on how this might be possible?

 

var a = (parseInt({Data.Session.ClosedTypeInt},10));
var b = (parseInt({Data.Element.10_Option_OptionEnable.value},10));
var c = a+b;
var str = c.toString();
eval (str);


---- Output from Log shows the value as a float ----

custom,Data.Element.10_Option_OptionEnable.value,7
custom,Data.Session.ClosedTypeInt, 20
custom,LocalVar.NewClosed1,27.0

 

Regards,

Gerry

1 Accepted Solution

Accepted Solutions

Bill Mungaven
Level 1
Level 1

The way I do this is to use .toFixed(0);

 

In my queue scripts, I check for calls in queue to let the caller know where they are in the queue. I have to add one then convert it to an integer using a Set Value element so it plays properly using Say It Smart. I do it like this:

var callsInQueue;

var ciq = {Data.Session.callsInQueue};

callsInQueue = (parseInt(ciq) + 1).toFixed(0);

 

I don't know if this is technically correct but it was the only way I could eliminate the .0 at the end of the value.

This returns an integer value rather than the float value.

 

I hope this helps.

View solution in original post

5 Replies 5

Quigath
Spotlight
Spotlight

This is just a javascript problem, right?

 

Have you tried something like:

var str = "" + c;

OR

var str = String(c);

 

 

ptindall
Cisco Employee
Cisco Employee

Math.floor(c) if you want a whole number.

String(Math.floor(c)) if you want it as a string.

Thanks Paul, thanks Quigath,

 

None of these work.

The var str = "" + c;

 

should work.

But even if you concatenate a number.

 

var c = 14;

var str = "1" + c;

This evaluates to 114.0 and not 114

 

No matter what I do - the value stays as a number and does not convert to a string.

I try a little Java class.

 

Gerry

Bill Mungaven
Level 1
Level 1

The way I do this is to use .toFixed(0);

 

In my queue scripts, I check for calls in queue to let the caller know where they are in the queue. I have to add one then convert it to an integer using a Set Value element so it plays properly using Say It Smart. I do it like this:

var callsInQueue;

var ciq = {Data.Session.callsInQueue};

callsInQueue = (parseInt(ciq) + 1).toFixed(0);

 

I don't know if this is technically correct but it was the only way I could eliminate the .0 at the end of the value.

This returns an integer value rather than the float value.

 

I hope this helps.

Bill,

 

That was exactly my problem (or very similar) - thanks a mil.

That is better than my approach and what I was looking for.

 

Gerry