Double formatting in C#

Results 1 to 2 of 2

Thread: Double formatting in C#

  1. #1
    Join Date
    Dec 1969

    Default Double formatting in C#

    Have any of you tried Jeff Prosise&#039;s ASP.NET Mortgage calculator code examples in MSDNmag? As they were merely examples and I am a poor typist, mine needed lots of debugging.<BR><BR>Part of the code involved converting a double to a string. It was like<BR><BR>strResult = Convert.ToString(dbPayment);<BR>Console.WriteLine = "Your monthly payment is " & strResult;<BR><BR>Should I create another variable that formats strResult as currency (just what I need, another variable to dote on), is there a way to reformat strResult as currency, or is there a way to just format dbPayment as currency and leave out the string conversion altogether?<BR><BR>Many thanks,<BR><BR>Thom

  2. #2
    Join Date
    Dec 1969

    Default RE: Double formatting in C#

    Use the following code:<BR><BR>String.Format("{0:c}", dbPayment)<BR><BR>You can also try this, although it&#039;s untested:<BR><BR>dbPayment.ToString("c")<BR><BR>bo th should do the trick, both without the need to create an strResult variable (since both return a string, properly formatted). hth

Posting Permissions

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