Results 1 to 2 of 2

Thread: Fixed Number of digits

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Fixed Number of digits

    How would I output a fixed number of digits. I DO NOT mean a fixed number of digits after the decimal point. I mean a fixed number of digits ALWAYS no matter what my number turns out to be.

    How can this be done in C# and in C if anyone knows.

    Thanks!

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Fixed Number of digits

    4 digits regardless of the number?
    int n = 34;
    Console.WriteLine(n.ToString("0000");

    This works if the number is less than 4 digits, now is the number is greater than 4 digits which ones are you going to get rid of?

    you can always create a custom format here's and example:
    http://authors.aspalliance.com/aspxt...atstrings.aspx
    Last edited by DeadEyes; Mar 31st, 2005 at 10:56 AM.

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