snippets / Format decimal places

Language: C# - First posted by qrist0ph on 2008-05-5 11:20 (2 months)
Link to the snippet: http://www.friendsnippets.org/snippet/281/

.

 1 public static void generatoRandomDouble()
2 {
3 Random random = new Random();
4 double r = random.NextDouble() * 100;
5 // cut of all but 2 decimal places
6 Console.WriteLine(r.ToString("#0.00"));
7 // round the doube
8 r= Math.Round(r, 2);
9 Console.WriteLine(r);
10 // use point "." as decimal point
11 Console.WriteLine(r.ToString(CultureInfo.InvariantCulture.NumberFormat));
12 }
In order to post a comment, you should have a friendsnippet account. Please sign-in.

0 comments

May '08

Common Tags


Related snippets


snippet History

May '08