Skip to main content
6-Contributor
May 8, 2018
Solved

How can I change data type and add entries of a Column of infotable?

  • May 8, 2018
  • 3 replies
  • 2735 views

I have service with output as Infotable, of which one of the column (Temperature) has some values but data type is String. How can I change Data Type of all the values and then add all the values.

Best answer by amittal-3

Hi Nikhil,

Understood your problem!!!. Well in that case you can use "Number()" of javascript. It can be used as follows, here I am converting a value formatted in string to just number.

 

var arr = { };
//for loop to get the values from your infotable
for(var i = 0; i < myInfoTable.getRowCount(); i++)
{
	arr[i] = Number(myInfoTable.getRow(i).Temperature); //Assuming that you have a column named as 'Temperature' in your infotable
}

I hope this helps

Thanks and Regards

Aditya Mittal

3 replies

1-Visitor
May 8, 2018

Hello,

I am sorry as I am not able to understand your requirement clearly.

But I'll try to put it in my words what I understood. So you have a infotable with one of its field of name Temperature of type string. Now while filling that infotable you would want to fill that 'Temperature' column with values of type string, for that you would need a mechanism to convert the actual temperature values (which actually are of number type) to string and then put it in the infotable. Is that understanding correct?

If this understanding is correct then simply when you are filling your infotable, instead of putting the values directly in the 'Temperature' field, you can use num.toString() method.

 

var temperatureVariable; //of type Number
//for loop to add rows to your infotable consecutively 
myInfotable.AddRow(
 {
 Temperature: temperatureVariable.toString()
 })

Let me know if it helps.

Thanks

Aditya

njain-316-ContributorAuthor
6-Contributor
May 8, 2018

Hi Aditya,

 

Thanks for your response. I want to change data type other way around, value of Temperature is in String Data type in my current infotable which I need to change it in Number.

 

Thank You

 

Nikhil 

amittal-31-VisitorAnswer
1-Visitor
May 9, 2018

Hi Nikhil,

Understood your problem!!!. Well in that case you can use "Number()" of javascript. It can be used as follows, here I am converting a value formatted in string to just number.

 

var arr = { };
//for loop to get the values from your infotable
for(var i = 0; i < myInfoTable.getRowCount(); i++)
{
	arr[i] = Number(myInfoTable.getRow(i).Temperature); //Assuming that you have a column named as 'Temperature' in your infotable
}

I hope this helps

Thanks and Regards

Aditya Mittal