473,769 Members | 6,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Currency,Decima l,Access and Confusion

Hi Everyone,

I'm trying to extract my pricing from my Access.mdb. Developing WinForm C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00, and
when I try to extract my data, it converts some how to just "10". How do I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?

Any and all help is appreciated,

MikeY
Apr 13 '06 #1
11 2968
MikeY wrote:
I'm trying to extract my pricing from my Access.mdb. Developing WinForm C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00, and
when I try to extract my data, it converts some how to just "10". How do I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?


There are three potential problems:
1) The precision of the data isn't coming across from the database
2) Convert.ToDecim al is being problematic
3) The way you're displaying it is problematic.

If you write:

Console.WriteLi ne (myDataReader["Price"].GetType());
Console.WriteLi ne (myDataReader["Price"].ToString());

what happens?

Jon

Apr 13 '06 #2
Hiya Jon,

I'm getting System.Decimal for the GetType();
I'm getting the Item price value as is should be. But for the "10.00" value
it is being shown as "10" (not correct), while the "9.95" is being displayed
as "9.95" (correct).

txs agian Jon,

MikeY
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
MikeY wrote:
I'm trying to extract my pricing from my Access.mdb. Developing WinForm
C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00,
and
when I try to extract my data, it converts some how to just "10". How do
I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?


There are three potential problems:
1) The precision of the data isn't coming across from the database
2) Convert.ToDecim al is being problematic
3) The way you're displaying it is problematic.

If you write:

Console.WriteLi ne (myDataReader["Price"].GetType());
Console.WriteLi ne (myDataReader["Price"].ToString());

what happens?

Jon

Apr 13 '06 #3
I do believe the problem lies in the data not coming across from the Access.

"MikeY" <mi*******@yaho .com> wrote in message
news:_B******** *********@news2 0.bellglobal.co m...
Hiya Jon,

I'm getting System.Decimal for the GetType();
I'm getting the Item price value as is should be. But for the "10.00"
value it is being shown as "10" (not correct), while the "9.95" is being
displayed as "9.95" (correct).

txs agian Jon,

MikeY
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
MikeY wrote:
I'm trying to extract my pricing from my Access.mdb. Developing WinForm
C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00,
and
when I try to extract my data, it converts some how to just "10". How do
I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?


There are three potential problems:
1) The precision of the data isn't coming across from the database
2) Convert.ToDecim al is being problematic
3) The way you're displaying it is problematic.

If you write:

Console.WriteLi ne (myDataReader["Price"].GetType());
Console.WriteLi ne (myDataReader["Price"].ToString());

what happens?

Jon


Apr 13 '06 #4

MikeY wrote:
Hi Everyone,

I'm trying to extract my pricing from my Access.mdb. Developing WinForm C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00, and
when I try to extract my data, it converts some how to just "10". How do I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?


The *number* 10 is the same however many zero digit decimal places you
append. The place you need to look (and show us if you don't see the
problem) is where you *display* the value.

Decimal.ToStrin g doesn't automatically know how you want your ten
displayed - it doesn't know it represents a currency value; it's just
ten. ToString has overloads that take formatting information - this is
a good place to start digging around the docs.

--
Larry Lard
Replies to group please

Apr 13 '06 #5
Hi Larry,

At present, I am extracting my Currency into a decimal value. From there I
do format the the value to be displayed in my ListView. My code is as
follows:

private void ctrl_Bottom1_my _Test(string myName, decimal myPrice)
{
string unitPrice = System.String.F ormat ("{0:C}", myPrice);

this.lvBody.Beg inUpdate();
this.lvBody..It ems.Add(myName) ;
this.lvBody.Ite ms[ListViewCounter].SubItems.Add(u nitPrice.ToStri ng());
this.lvBody.End Update();

ListViewCounter += 1;
}

This way does work, But I wonder why I am loosing my .00 cents (of the
10.00) from the database when non-zero (9.95) characters are good. And if
there is a better way.

So gather what your wrote is that the only way to get the lots .00 is to
append the zeros back in. Like I am doing with the code above. Hmmmm

Thanks Larry,

MikeY

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .

MikeY wrote:
Hi Everyone,

I'm trying to extract my pricing from my Access.mdb. Developing WinForm
C#.
I've read previous posts on the subject, but I'm still confused.

In Access my "Price" is of "Currency" type. I extract my items
"myDataItem.MyP rice(Convert.To Decimal(myDataR eader["Price"]));

Now my problem like so many others is that if my dollar value is $10.00,
and
when I try to extract my data, it converts some how to just "10". How do
I
loose the ".00" decimal and the cents? If I have $10.99 value, all is
displayed correctly. Why does this do that, and what do I need to do to
correct this problem. As stated in past posts do I just need to take the
"10" and build a string.Format to rebuild/add the .00 decimal and cents?


The *number* 10 is the same however many zero digit decimal places you
append. The place you need to look (and show us if you don't see the
problem) is where you *display* the value.

Decimal.ToStrin g doesn't automatically know how you want your ten
displayed - it doesn't know it represents a currency value; it's just
ten. ToString has overloads that take formatting information - this is
a good place to start digging around the docs.

--
Larry Lard
Replies to group please

Apr 13 '06 #6
Larry Lard <la*******@hotm ail.com> wrote:
Decimal.ToStrin g doesn't automatically know how you want your ten
displayed - it doesn't know it represents a currency value; it's just
ten.
No, that's not true. Decimal (unlike, say, float and double) *does*
maintain the number of decimal places it considers itself to represent.
So 10, 10.0 and 10.00 are differently represented. Try the following:

using System;

class Test
{
static void Main()
{
decimal d1 = 10m;
decimal d2 = 10.0m;
decimal d3 = 10.00m;
Console.WriteLi ne ("{0} {1} {2}", d1, d2, d3);
}
}

(Try the equivalent with floats and you'll get a different answer.)
ToString has overloads that take formatting information - this is
a good place to start digging around the docs.


Yes, that's probably the easiest way of "forcing" it to a certain
number of decimal places.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 13 '06 #7
MikeY <mi*******@yaho .com> wrote:
I do believe the problem lies in the data not coming across from the Access.


Right. In that case, I believe the best solution is to format the
number as you want it when you turn it into text.

There's no "obvious" way of forcing the decimal itself to 2 decimal
places. In a couple of tests, adding 1.00m and then subtracting it
again works, but I wouldn't like to swear that it's guaranteed to - and
it's the kind of code which is likely to get removed by a maintenance
programmer as it looks like a no-op. Choosing an appropriate format
string is clearer, IMO.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 13 '06 #8
Thanks again Jon for the response and the confirmation. I'll just stick with
the way I have it then.

MikeY

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
MikeY <mi*******@yaho .com> wrote:
I do believe the problem lies in the data not coming across from the
Access.


Right. In that case, I believe the best solution is to format the
number as you want it when you turn it into text.

There's no "obvious" way of forcing the decimal itself to 2 decimal
places. In a couple of tests, adding 1.00m and then subtracting it
again works, but I wouldn't like to swear that it's guaranteed to - and
it's the kind of code which is likely to get removed by a maintenance
programmer as it looks like a no-op. Choosing an appropriate format
string is clearer, IMO.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 13 '06 #9
Thanks again Jon, I'll give it a try.

MikeY

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Larry Lard <la*******@hotm ail.com> wrote:
Decimal.ToStrin g doesn't automatically know how you want your ten
displayed - it doesn't know it represents a currency value; it's just
ten.


No, that's not true. Decimal (unlike, say, float and double) *does*
maintain the number of decimal places it considers itself to represent.
So 10, 10.0 and 10.00 are differently represented. Try the following:

using System;

class Test
{
static void Main()
{
decimal d1 = 10m;
decimal d2 = 10.0m;
decimal d3 = 10.00m;
Console.WriteLi ne ("{0} {1} {2}", d1, d2, d3);
}
}

(Try the equivalent with floats and you'll get a different answer.)
ToString has overloads that take formatting information - this is
a good place to start digging around the docs.


Yes, that's probably the easiest way of "forcing" it to a certain
number of decimal places.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6149
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
4
22597
by: Gerry Abbott | last post by:
Hi All. How can i put a zero decimal for my currency into my format statement, == & ", for " & & " days. Cost " & Format(,"Currency") which is the data source for a textbox on a report
4
9425
by: digitalavatar | last post by:
I am having a problem with my Access 2000 front end to a SQL 7 or 2000 database. I create a table in SQL with a field named, say, amt, data type MONEY. When I link the table in Access using ODBC, the field is defined as CURRENCY, as expected. Now, if I use SQL to populate the field with a 3- or 4-decimal amount like 1.234, it appears in the Access table as 1.23 only. If I expand the decimals to 3 places it will be 1.230; if the...
3
2040
by: Dave Stone | last post by:
This question appeared years ago in the context of Acc2K and SQL Server 7, but no replies were posted. HOWEVER!! It still seems to be a problem with Acc XP and SQL Server 2000. Surely someone has a fix 6 years down the line... I used the Upsizing Wizard to build a SQL database from an Access back-end and link it to the Access f/e. All the data appear to have gone across OK as viewed from Enterprise Manager, but from the front-end all...
2
2866
by: David Nunn | last post by:
Need to preface that I am not much of an Access type. Doing I have several tables that have currency fields, which I run queries against to compare the figures in both. The data is imported from Excel spreadsheets supplied by different parties, over which I have no control. My problem is that whilst several parties supply the spreadsheets with the currency fields containing two figures to the right of the decimal place (ie 123.51,...
3
24403
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be currency and others when it will be a text integer or decimal. //This bombs because of the string having an improper format. Decimal.Parse("$9,200.00") Thanks in advance! Mark
11
2957
by: Adrian | last post by:
Hi I want to use the following declarations but vb dotnet keeps complaining that currency can't be used because it private ? I have tried it in a module and in the declaration pare same error! Private Declare Function QueryPerformanceFrequency Lib "kernel32" (ByVal
2
3653
by: crazytegger | last post by:
Hi all, Im having trouble with currency formatting and the amount of decimals displayed. Most of my stored values are pretty standard ($10.50). Some item have a 4 decimal place cost though ($.0025). I have the table formatted to store 4 decimal places but when using the currency format it drops the last two places of the value. Is there a way around this or do i have to use general number format for the table? I also dont want the field to...
14
4361
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my unformatted data values (as decimals) just fine, so I know there's not a problem with the data retrieval, just the formatting. I have read that this would work: lblPrice.Text = prodRow.ToString("C");
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.