Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,

I am adding two rows which contain floating point numbers and placing them into different row

I am using following code to do that


xlWorkSheet1.Cells[i, 5] = float(Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]));

But I am getting following error:

Error1 Invalid expression term 'float'


Can anyone help me in solving this


Thanks
John
Posted

Try:
xlWorkSheet1.Cells[i, 5] = (float)(Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]));

But is there a reason why you are converting them to integer first? Wouldn't it be more obvious if you converted them to float or double values instead?
 
Share this answer
 
convert this row also float type
xlWorkSheet1.Cells[i, 5])

or

write like this(float)
 
Share this answer
 
Compiler Error CS1525 means you didn't well know about casting. You can fix it by (float) instead of float. More clearly about Error CS1525, see below.
http://msdn.microsoft.com/en-us/library/3hdyz4dw(v=vs.90).aspx[^]
 
Share this answer
 
You can Try any one of the following ways as

C#
float floatValue = (float)(Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]));

(or)
C#
float floatValue1 =  float.Parse((Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13])).ToString()); 

(or)
C#
float floatValue2 = (float)row[13] + (float)row1[13];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900