CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    82

    Currency formatting

    Hi,
    I have some currency values to be formatted. They are stored as double and when I use String.Format("{0:C2}", strValue); it does NOT yield the right results.

    I need all the values to be formatted to decimal places e.g 124 as 124.00 and 123.45 as 123.45 itself. I also want the -values to be surrounded by parenthesis. I knew how to do this in VB but not in C#! Like -123.56 should be (123.56) and -34 should (34.00).

    I read some articles but they just dont give me the output what I want above. Ther eis one at:
    http://blog.stevex.net/c-string-formatting-faq/

    Any help would be greatly appreciated. Thank you.

  2. #2
    Join Date
    Jul 2010
    Posts
    82

    Re: Currency formatting

    Note: Using
    Double dVal = Double.Parse(strValue).ToString("N");

    gives a pretty decent formatted output. How can I use () to show -ve values I would like to show 3 decimal places. Like 123.4567 as 123.457.

    Using the "N" formats it to 2 decimal places.

  3. #3
    Join Date
    Jan 2007
    Location
    .NET 3.5
    Posts
    38

    Re: Currency formatting

    decimal rounded = decimal.Round( Argument, Digits );

    http://msdn.microsoft.com/en-us/libr...nd(VS.71).aspx

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Currency formatting

    Quote Originally Posted by CuteAssistant View Post
    Note: Using
    Double dVal = Double.Parse(strValue).ToString("N");

    gives a pretty decent formatted output. How can I use () to show -ve values I would like to show 3 decimal places. Like 123.4567 as 123.457.

    Using the "N" formats it to 2 decimal places.
    Read up on the "N" formatter here:
    http://msdn.microsoft.com/en-us/libr...#NFormatString

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured