"." custom specifier in C#


The "." custom format specifier adds a localized decimal separator into the output string.

The 1st period in the format string determines the location of the decimal separator in the formatted value.

double d = 2.3;
d.ToString("0.00", CultureInfo.InvariantCulture

Let us see another example to learn how to implement “.” Custom specifier.

Example

 Live Demo

using System;
using System.Globalization;
class Demo {
   static void Main() {
      double d;
      d = 3.7;
      Console.WriteLine(d.ToString("0.00", CultureInfo.InvariantCulture));
      Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:0.00}", d));
      d = 5.89;
      Console.WriteLine(d.ToString("00.00", CultureInfo.InvariantCulture));
      Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:00.00}", d));
   }
}

Output

3.70
3.70
05.89
05.89

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

138 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements