Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pvong - 03 Oct 2007 02:56 GMT
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
Martin CLAVREUIL - 03 Oct 2007 06:42 GMT
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.
>
[quoted text clipped - 7 lines]
>
> AmountTB.Text = AmountMoney.ToString
RB - 03 Oct 2007 11:41 GMT
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.

> Hi,
>
[quoted text clipped - 17 lines]
>>
>> AmountTB.Text = AmountMoney.ToString

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.