473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Show money from a database

I have a decimal field in a SQL Server DataBase who stores money and I want
to show it in a TextBox and in a ListView controls in C#.

If I do: txtMoney.Text = Convert.ToSingle(dr["money"]);
I see something like: "4.0000" instead "4.00 ?"

How can I solve this?

Thank you very much
Nov 16 '05 #1
2 4805
Alberto,

Basically, you would want to get the currency format for the system, and
then display that. You can do this easily through the ToString method on
the numeric type that is returned.

You don't need to call the static ToSingle method on the Convert class.
Rather, you can just cast it to your type, like so:

// Cast to the value.
// Float is the C# type alias for Single.
float money = (float) dr("money");

// Write in currency format.
txtMoney.Text = money.ToString("C");

The "C" indicates to use the currency format currently defined for the
thread (which is usually the local machine's setting). Just make sure that
the currency that the amount is in is the same as the one on the local
machine. Otherwise, you will have to get the setting for the region, and
then use that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Alberto" <al*****@nospam.es> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
I have a decimal field in a SQL Server DataBase who stores money and I want
to show it in a TextBox and in a ListView controls in C#.

If I do: txtMoney.Text = Convert.ToSingle(dr["money"]);
I see something like: "4.0000" instead "4.00 ?"

How can I solve this?

Thank you very much

Nov 16 '05 #2
Thank you very much. I didn't find anything about this in any book.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> escribió
en el mensaje news:eC**************@tk2msftngp13.phx.gbl...
Alberto,

Basically, you would want to get the currency format for the system,
and then display that. You can do this easily through the ToString method
on the numeric type that is returned.

You don't need to call the static ToSingle method on the Convert class.
Rather, you can just cast it to your type, like so:

// Cast to the value.
// Float is the C# type alias for Single.
float money = (float) dr("money");

// Write in currency format.
txtMoney.Text = money.ToString("C");

The "C" indicates to use the currency format currently defined for the
thread (which is usually the local machine's setting). Just make sure
that the currency that the amount is in is the same as the one on the
local machine. Otherwise, you will have to get the setting for the
region, and then use that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Alberto" <al*****@nospam.es> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
I have a decimal field in a SQL Server DataBase who stores money and I
want to show it in a TextBox and in a ListView controls in C#.

If I do: txtMoney.Text = Convert.ToSingle(dr["money"]);
I see something like: "4.0000" instead "4.00 ?"

How can I solve this?

Thank you very much


Nov 16 '05 #3

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

Similar topics

3
by: Robby Russell | last post by:
Should be a simple question. When selecting a field that is of type money, how can I remove the $ when selected? example: $10.00 would return as 10.00 -Robby
12
by: David Garamond | last post by:
What do people recommend for storing money amounts? I've seen people use NUMERIC(18,3) and other use NUMERIC(18,4). Which one is more appropriate and why? This is considering various existing...
14
by: Ina Schmitz | last post by:
Hello all, I don't succeed in displaying the explain plan. I use IBM DB2 Universal Database 8.2. I tried to do the example given in the online help for "Visual Explain". The tables...
3
by: Alberto | last post by:
How can I show money in a label? Actully I have a decimal variable and I want to show it to the user like if it where money. For example: 5.00 ? Thank you
3
by: Artek | last post by:
Hello, after installing .net 1.1, ASP.NET works fine, but there is a problems with extra zeros added to the numbers at the end. In Sql 2000 SP3a there is for example a table with one column ...
45
by: Master Programmer | last post by:
- Constant language / system changes - Dropping of the VB language - Security configuation minefields - Loss of old code base - Time consuming to learn (then it changes every 5 minutes) - Slow...
5
by: Ronald S. Cook | last post by:
For money values, C# seems to have just DOUBLE as a type. SQL Server 2005 has data types DECIMAL, FLOAT, MONEY, and NUMERIC that seem to all be able to hold a money time. So, given I'll be...
4
by: Ronald S. Cook | last post by:
We're designing the data model for a project. The app will be in .NET, the database will be in SQL Server 2005. I'm a little confused on type conversion between the two and which I should...
0
by: CaJack | last post by:
Hi, I'm having some trouble with my asp.net page and my sql database. What I'm trying to do is allow the user to upload an number to the database, the number is a money amount like 2.00 (£2.00) or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.