Arpit Posted January 13, 2002 Share Posted January 13, 2002 okay c# programmers...have a stupid question to ask of you...how do i specify the number of decimal places for a double/decimal value?? in C++ it's cout.precision(*no. of digits*)...but can't seem to find something like this for C#...please help :) Link to comment Share on other sites More sharing options...
0 neowin_hipster Posted January 13, 2002 Share Posted January 13, 2002 try checking www.msdn.microsoft.com Link to comment Share on other sites More sharing options...
0 freestyle Posted January 15, 2002 Share Posted January 15, 2002 You could do something like this: <pre> double dblPi = 22/7f; Console.WriteLine("pi = {0}", dblPi); Console.WriteLine("pi to 10 Decimal Places = {0:F10}", dblPi); Console.WriteLine("pi to 5 Decimal Places = {0:F5}", dblPi); Console.WriteLine("pi to 2 Decimal Places = {0:F2}", dblPi); Console.WriteLine("pi to 0 Decimal Places = {0:F0}", dblPi); </pre> Would produce output, like this: <pre> pi = 3.14285714285714 pi to 10 Decimal Places = 3.1428571429 pi to 5 Decimal Places = 3.14286 pi to 2 Decimal Places = 3.14 pi to 0 Decimal Places = 3 </pre> Link to comment Share on other sites More sharing options...
0 Arpit Posted January 15, 2002 Author Share Posted January 15, 2002 thanks a lot!!!...another question...what is the difference between namespace and classes? Link to comment Share on other sites More sharing options...
0 freestyle Posted January 16, 2002 Share Posted January 16, 2002 To quote from the MSDN A class is a template or blueprint that defines the characteristics of an object and describes how the object should look and behave.A namespace is a logical unit for grouping classes and class instances, and for controlling their scope and visibility. Link to comment Share on other sites More sharing options...
Question
Arpit
okay c# programmers...have a stupid question to ask of you...how do i specify the number of decimal places for a double/decimal value??
in C++ it's cout.precision(*no. of digits*)...but can't seem to find something like this for C#...please help :)
Link to comment
Share on other sites
4 answers to this question
Recommended Posts