PC Review


Reply
Thread Tools Rate Thread

C# Excel Interop and Decimal Places

 
 
Matt
Guest
Posts: n/a
 
      17th Feb 2009
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 With Quote
 
 
 
 
jaf
Guest
Posts: n/a
 
      18th Feb 2009
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" <(E-Mail Removed)> wrote in message news:03aaf353-1147-4ca8-aeb2-(E-Mail Removed)...
>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 With Quote
 
New Member
Join Date: Apr 2008
Posts: 13
 
      9th Apr 2009
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;

http://csharp.net-informations.com/e...read-excel.htm

tks.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed decimal places in Excel Garben Microsoft Excel Misc 4 9th Dec 2008 09:49 PM
decimal places in acces more than 2 places when importing an excel =?Utf-8?B?cm9iZXJ0cm9iZXJ0cm9iZXJ0cm9iZXJ0?= Microsoft Outlook Discussion 2 28th Sep 2005 04:41 PM
Decimal places in Excel 2003 =?Utf-8?B?RVhDRUxOQ0JPWQ==?= Microsoft Excel Worksheet Functions 6 5th Nov 2004 03:39 PM
excel vba - format decimal places chief Microsoft Excel Misc 2 25th Aug 2004 09:21 PM
Excel Decimal Places Harry Microsoft Excel Worksheet Functions 1 20th Apr 2004 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 AM.