How to Specify the Number of Decimal Places for a Double value in C# ?

Published on May 25, 2014 by abundantcode

Filed under C#

Last modified May 25, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3295 times

Below is a sample code snippet that demonstrates how the developers can specify the number of decimal places for a number declared as double in C#.

How to Specify the Number of Decimal Places for a Double value in C# ?

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            // How to Specify the Number of Decimal Places for a Double value in C# ?
            double Input = 1007.8675;
            Console.WriteLine(Input.ToString("F2", CultureInfo.InvariantCulture));
            Console.ReadLine();
        }
    }
    
}

1

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to Group Digits of a Number for Formatting in C# ?

If you want to group the digits of a number for formatting to display in C# , one could use the "N" ...

How to Format a Number for a Specific Culture in C# ?

Below is a sample code snippet demonstrating how to format the number for a specific culture in C# ....

General Numeric Formatting in C#

Below is a sample source code demonstrating General Numeric Formatting(G) string in C# .using Sy...