473,383 Members | 1,813 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,383 software developers and data experts.

Simple Convert String to Decimal with 2 places to the right.

Newbie learning VB.Net.

I have a simple DataReader and I can grab the info. The data is in numeric
format like 123.99 and I want a TextBox to just display it just like that.
When I use the code below, I get 123.9900 and I don't know how to get rid of
the last 2 zeros. I thought for sure the below would work but it didn't.
Thanks in advance.
----------------------
Dim AmountMoney As Decimal = CType(dr.Item("Amount"), Decimal)

AmountTB.Text = AmountMoney.ToString
Oct 3 '07 #1
2 3826
Hi,

The 'string ToString(string format)' method allready provides the same
fonctionality. In C# it looks likr this :

decimal d = (decimal)123.9900;
Console.WriteLine(d.ToString("N2"));

pvong write :
Newbie learning VB.Net.

I have a simple DataReader and I can grab the info. The data is in numeric
format like 123.99 and I want a TextBox to just display it just like that.
When I use the code below, I get 123.9900 and I don't know how to get rid of
the last 2 zeros. I thought for sure the below would work but it didn't.
Thanks in advance.
----------------------
Dim AmountMoney As Decimal = CType(dr.Item("Amount"), Decimal)

AmountTB.Text = AmountMoney.ToString

Oct 3 '07 #2
RB

Reading between the lines of your question, and in addition to Martin's
answer, it looks like you are getting a field from a database, which has
been declared as "money", and you want to display it as a currency.

Firstly, a lot of people don't use the "money" datatype, and instead use
something along the lines of "decimal (12, 2)", as they find it easier
to work with - google about why the money datatype is evil will get lots
of argument (for and against!!)

Secondly, you can actually format a number as a currency. Using Martin's
example:

decimal d = (decimal)123.9900;
Console.WriteLine(d.ToString("c"));

As I say, I'm reading between the lines, so apologies if this is not
relevant!

HTH,

Rowland.

Martin CLAVREUIL wrote:
Hi,

The 'string ToString(string format)' method allready provides the same
fonctionality. In C# it looks likr this :

decimal d = (decimal)123.9900;
Console.WriteLine(d.ToString("N2"));

pvong write :
>Newbie learning VB.Net.

I have a simple DataReader and I can grab the info. The data is in
numeric format like 123.99 and I want a TextBox to just display it
just like that. When I use the code below, I get 123.9900 and I don't
know how to get rid of the last 2 zeros. I thought for sure the below
would work but it didn't.
Thanks in advance.
----------------------
Dim AmountMoney As Decimal = CType(dr.Item("Amount"), Decimal)

AmountTB.Text = AmountMoney.ToString


Oct 3 '07 #3

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

Similar topics

17
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....
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Bubba | last post by:
I know it's possible, just don't know how to do it. I have a spreadsheet that I imported into access. Two of the columns in the table have Hard Drive space values listed for example 2.45 GB and 453...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
6
by: Justin | last post by:
I am trying to add dollar amounts together and add sales tax but everthing after the decimal point is being cut off in the dollar amounts. Here is my code: if (Adults != "") { AdultTotal =...
6
by: Jim Stools | last post by:
How do I do this: result needs to be a decimal to 2 places? I get casting problems on the below: double myPrice = 1200.125;double myShares = 354.288; decimal myTotal; myTotal = myPrice *...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.