double value format vs int value format
using System;
using System.Globalization;
using System.Threading;
public class NumericFormats
{
public static void Main()
{
CultureInfo ci = new CultureInfo("en-us");
double floating = 1234567.987654321;
Console.WriteLine("C: {0}", floating.ToString("C", ci));
Console.WriteLine("E: {0}", floating.ToString("E03", ci));
Console.WriteLine("F: {0}", floating.ToString("F04", ci));
Console.WriteLine("G: {0}", floating.ToString("G", ci));
Console.WriteLine("N: {0}", floating.ToString("N03", ci));
Console.WriteLine("P: {0}", (floating/10000).ToString("P02", ci));
Console.WriteLine("R: {0}", floating.ToString("R", ci));
// Output integral values
int integral = 9999;
Console.WriteLine("C: {0}", integral.ToString("C", ci));
Console.WriteLine("D: {0}", integral.ToString("D6", ci));
Console.WriteLine("E: {0}", integral.ToString("E03", ci));
Console.WriteLine("F: {0}", integral.ToString("F01", ci));
Console.WriteLine("G: {0}", integral.ToString("G", ci));
Console.WriteLine("N: {0}", integral.ToString("N01", ci));
Console.WriteLine("P: {0}", (integral/10000.0).ToString("P02", ci));
Console.WriteLine("X: 0x{0}", integral.ToString("X", ci));
}
}
/*
C: $1,234,567.99
E: 1.235E+006
F: 1234567.9877
G: 1234567.98765432
N: 1,234,567.988
P: 12,345.68 %
R: 1234567.9876543209
C: $9,999.00
D: 009999
E: 9.999E+003
F: 9999.0
G: 9999
N: 9,999.0
P: 99.99 %
X: 0x270F
*/
Related examples in the same category