Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] string format help..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Resolved [RESOLVED] [2.0] string format help..

    I am formatting a string.

    If there is "0" in the string, I would like to show, 0.00 .

    I am using currently the following code that shows 0.0000

    string.Format("{0:#,##}",custObject.xx.ToString());

    could some one give me some help.

    thanks
    nath

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] string format help..

    Using formats like that only works if you are formatting a number, not a string. Just because your string includes digit characters doesn't make it a number. You are converting the number to a string with the ToString method, so any format you use in String.Format is useless. Remove the ToString call and you should find that it works. That's because the number will only be converted to a string when the actuall formatting is applied. Note also that if you want the standard numerical format for the current system with two decimal places you should use "n2" as the format string.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: [2.0] string format help..

    you suggestion n2 works.

    thanks
    nath

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