Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
C# Excel Interop and Decimal Places
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
C# Excel Interop and Decimal Places
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 "Matt" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Fixed decimal places in Excel | Excel Discussion (Misc queries) | |||
Subtracting two 2-decimal place numbers gives result 13-decimal places? | Excel Worksheet Functions | |||
Excel dropping decimal places | Excel Programming | |||
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. | Excel Discussion (Misc queries) | |||
Decimal places in Excel 2003 | Excel Worksheet Functions |