XTab's Blog

Ged Mead's Blog at vbCity

vbCity Blogs moved to:
http://cs.vbcity.com/blogs
  Home :: Syndication  :: Login

OctNovember 2009Dec
SMTWTFS
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Archives

Topics

Ramblings

VB.NET

  Here's a useful little tip for if you have a numeric value and you need to convert it into your local currency.

  Let's assume you take in a value as a Double and you want the output to be in the format of currency, with two decimal places (in the case of the UK to represent Pence).

  Here's the Double:

Code Copy
     Dim TotalCost As Double = 123.4567

  To show this formatted, you can use the String.Format method, a placeholder for the variable and the 'c' attribute to ensure the currency format is used:

Code Copy
       Label1.Text = String.Format("Total Cost = {0:c}", TotalCost)

  The result would look like this:

  

  Notice that it automatically rounds up for you, changing '4567' to '46'.

posted on Friday, July 31, 2009 8:47 PM

Feedback

No comments posted yet.

Post Feedback

Title:
Name:
Url:
Comments: 
Protected by Clearscreen.SharpHIPEnter the code you see: