I'm trying to get the decimal point to show with one digit of precision
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: I'm trying to get the decimal point to show with one digit of precision

  1. #1
    Join Date
    Mar 2005
    Posts
    13

    I'm trying to get the decimal point to show with one digit of precision

    Okay I have an int variable and a double variable. The int is set to 10. The double is set to 10.0. To my surprise when I went to view the output both said 10. There was no .0 to the right on the double variable.

    Not sure why that is but I'm trying to find a way to tell Console.WriteLine() to print the double as 10.0. Here is what I got so far but this prints 2 digits instead of 1:

    int ivar;
    double dvar;

    ivar = 10;
    dvar = 10.0;

    Console.WriteLine("The original value of ivar: " + ivar);
    Console.WriteLine("The original value of dvar: {0:f}", dvar);

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,966

    Re: I'm trying to get the decimal point to show with one digit of precision

    Look in msdn for string format specifiers.

  3. #3
    Join Date
    May 2009
    Posts
    32

    Re: I'm trying to get the decimal point to show with one digit of precision

    Code:
       class Program
        {
            static void Main(string[] args)
            {
                int ivar = 10;
                double dvar = 10.0;
    
                Console.WriteLine("The original value of ivar: " + ivar);
                Console.WriteLine("The original value of dvar: {0}", dvar.ToString("00.0"));
    
                   
            }
        }

  4. #4
    Join Date
    Jan 2014
    Posts
    1

    Re: I'm trying to get the decimal point to show with one digit of precision

    Here is an example.

    /// <summary>
    /// Gets the displayed format of the current count
    /// </summary>
    public string DisplayedCount
    {
    get { return String.Format("{0:0.00000}", this.countValue); }
    }

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center