Maha

Maha

  • NA
  • 0
  • 328.4k

NP135 String.Format()

Aug 24 2008 3:35 PM

Hi Guys

 

NP135 String.Format()

 

In the following program String.Format() method (highlighted in yellow) return is 1.768866e+004.    

 

This can be understood.

      17688.66 = 1.768866 x 10exponential4 = 1.768866e+4.

 

But how can 1.768866e+004 be explained?

 

Though int x = 21; String.Format() method (highlighted in blue) is returning 15. Please explain the reason.

 

Thank you

 

using System;

 

class MainClass

{

    public static void Main()

    {

        double v = 17688.65849;

        double v2 = 0.15;

        int x = 21;

 

        string str = String.Format("{0:F2}", v);

        Console.WriteLine(str);     //17688.66

 

        str = String.Format("{0:N5}", v);

        Console.WriteLine(str);     //17,688.65849

 

        str = String.Format("{0:e}", v);

        Console.WriteLine(str);     //1.768866e+004

 

        str = String.Format("{0:r}", v);

        Console.WriteLine(str);     //17688.65849

 

        str = String.Format("{0:p}", v2);

        Console.WriteLine(str);     //15.00 %

 

        str = String.Format("{0:X}", x);

        Console.WriteLine(str);     //15

 

        str = String.Format("{0:D12}", x);

        Console.WriteLine(str);     //000000000021

 

        str = String.Format("{0:C}", 189.99);

        Console.WriteLine(str);     //$189.99

    }

}


Answers (2)