Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed decimal places in Excel Garben Excel Discussion (Misc queries) 4 December 9th 08 09:49 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Excel dropping decimal places [email protected] Excel Programming 7 October 28th 06 01:47 AM
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. SUKYKITTY Excel Discussion (Misc queries) 3 July 6th 05 01:50 PM
Decimal places in Excel 2003 EXCELNCBOY Excel Worksheet Functions 6 November 5th 04 03:39 PM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"