Hey there, I'm Rowan. I'm currently studying Software Engineering at UTM, and I'm also an IT Entrepreneur. This is my programming blog - you'll find loads of C# stuff in here, as well as MySQL and C tutorials with source. Comments are most welcome.
I too, am a bug within Māyā.
My Other Blog(s) and Site(s)
Friend sites and blogs
My Recent Posts
My C-Sharp Ideas
Thursday, July 21, 2005
A few basic things
There are quite a few things to know before really getting the hang of C#, and I believe that learning about how to format numbers that need to be output is something pretty basic, that many programmers disregard. However, here's a basic tutorial about controlling the number of decimal places that a decimal type displays.
Let's move on directly to the code. It's simple. Nothing complicated to understand. Check it out:
Notice that I've included System.Globalization in the usings. This is a namespace that is required in order to use the NumberFormatInfo class.
What I did was basically to instantiate a NumberFormatInfo class, and play with the NumberDecimalDigits property (which I kept incrementing). Watch the results on a console :) Also, note the use of the overloaded ToString() method, in which I passed two parameters, namely a string ("N"), and the NumberFormatInfo class that I instantiated.
Hope this little code snippet helps!
Thanks a lotta dude ;) Am using SharpDevelop 3.0 Beta 1 and your example help a lot, make more such "simple" tutorials, i'll appreciate it as many others who 're joining into c#, i guess !Post a Comment