C# Excel Interop and Decimal Places

M

Matt

I am reading in a sheet from Excel using the COM interop library
and .Net 2.0. The sheets themselves will be generated in Excel using
any version from Excel 87 to Excel 2007.

I have run into an issue where numbers appear to be losing their zero
based decimal places: i.e. 45.00 becomes 45 and 45.10 becomes 45.1.
We have asked the clients filling in these sheets to use a specific
number of decimal places - so they are entering 45.00 - but I am not
capturing that.

Right now I am grabbing a range and reading it into an object array.
When I look at the values in the range I even see 45.00 from the sheet
as 45.0. As soon as I ToString() the value ( I have too the database
is all varchar and I have no control over this) - I even lose the .0
and have just 45.

Right now I am reading a range into an object:

object[,] values = (object[,]) rng.Value2;

Is there another way to approach this problem? I can always assume
that 45 = 45.00 but I would rather be able to grab exactly what they
enter - so if they aren't doing it properly we can catch it.

Thanks,

Matt
 
J

jaf

Hi Matt,
In Excel 45.00=45. Trailing zero's are mathematically insignificant.
The .00 is visual formatting for the human interface regardless of what the user enters.

If you need them in your C app. you will need to format the incoming data.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top