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.MyPrice(Convert.ToDecimal(myDataRe ader["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 11 2906
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.MyPrice(Convert.ToDecimal(myDataRe ader["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.ToDecimal is being problematic
3) The way you're displaying it is problematic.
If you write:
Console.WriteLine (myDataReader["Price"].GetType());
Console.WriteLine (myDataReader["Price"].ToString());
what happens?
Jon
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.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.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.MyPrice(Convert.ToDecimal(myDataRe ader["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.ToDecimal is being problematic 3) The way you're displaying it is problematic.
If you write:
Console.WriteLine (myDataReader["Price"].GetType()); Console.WriteLine (myDataReader["Price"].ToString());
what happens?
Jon
I do believe the problem lies in the data not coming across from the Access.
"MikeY" <mi*******@yaho.com> wrote in message
news:_B*****************@news20.bellglobal.com... 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.com> wrote in message news:11**********************@i40g2000cwc.googlegr oups.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.MyPrice(Convert.ToDecimal(myDataRe ader["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.ToDecimal is being problematic 3) The way you're displaying it is problematic.
If you write:
Console.WriteLine (myDataReader["Price"].GetType()); Console.WriteLine (myDataReader["Price"].ToString());
what happens?
Jon
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.MyPrice(Convert.ToDecimal(myDataRe ader["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.ToString 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
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.Format ("{0:C}", myPrice);
this.lvBody.BeginUpdate();
this.lvBody..Items.Add(myName);
this.lvBody.Items[ListViewCounter].SubItems.Add(unitPrice.ToString());
this.lvBody.EndUpdate();
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*******@hotmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.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.MyPrice(Convert.ToDecimal(myDataRe ader["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.ToString 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
Larry Lard <la*******@hotmail.com> wrote: Decimal.ToString 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.WriteLine ("{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.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
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.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
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.com> wrote in message
news:MP************************@msnews.microsoft.c om... 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.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Thanks again Jon, I'll give it a try.
MikeY
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Larry Lard <la*******@hotmail.com> wrote: Decimal.ToString 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.WriteLine ("{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.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
On Thu, 13 Apr 2006 11:22:11 -0400, "MikeY" <mi*******@yaho.com> 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.MyPrice(Convert.ToDecimal(myDataReade r["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
moneyString = string.Format("${0:0.00}", yourDecdimalNumber);
Good luck with your project,
Otis Mukinfus http://www.arltex.com http://www.tomchilders.com
Hi Otis, Thanks for the response I'll give it a go and see how your syntax
works out.
Thanks again
MikeY
"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:2g********************************@4ax.com... On Thu, 13 Apr 2006 11:22:11 -0400, "MikeY" <mi*******@yaho.com> 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.MyPrice(Convert.ToDecimal(myDataRead er["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
moneyString = string.Format("${0:0.00}", yourDecdimalNumber);
Good luck with your project,
Otis Mukinfus http://www.arltex.com http://www.tomchilders.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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....
|
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
|
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,...
|
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...
|
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...
|
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...
|
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!...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| | |