We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert cell's format from general to double

Hi,

I tried to convert cell’s format from general to double, it shown exception in dll version 17.3.0.0. But it is working in version 7.1.

Note: Here we have attached sample files (code and input Excel), unit test file and Issue in image.

Thanks
Renga.

Hi,


Thanks for your posting and using Aspose.Cells.

We have looked into this issue and found that, you have integer (i.e. cell A2) inside your Excel file but you are expecting double value. So, it is not a bug but your code should expect integer not double.

If it was working in older version, then it means, older version had a bug.

If you still think, it is a bug, then please let us know what makes you think that value 1 is a double and not integer? Is there any such thing in Microsoft Excel which could tell us its data type? We will then look into this issue further.

So please change your code

Assert.AreEqual(1d, result[1, 0]);

into

Assert.AreEqual(1, result[1, 0]);

and it will fix your exception issue.

Besides, you can convert your cell A2 value into double like this and it works fine.

C#
double d = double.Parse(result[1, 0].ToString());

Thank you and have a good day.

Hi,


Thanks for using Aspose.Cells.

It is to inform you further that for cell’s numeric value in older versions, it is ambiguous for int and double values. It depends on many factors such as file format, user input, …etc. So, it is very possible that some cell values seem same for users but were exported as different object type for different cell. In newer versions, we unified the numeric values for some APIs. For Cell.Value, we always keep one double value for cell’s numeric values. For Cells.ExportArray, we always check whether the double object is in fact an integer value, if so we export it as int object for the resultant array. So, for the resultant array, if one numeric value is an integer, please use int instead of double to do the comparison.