"." 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
Updated on: 2020-06-23T09:02:33+05:30

242 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements