-3

I want to display the answer up to four decimal places after round off. I have tried many functions but all are giving same answer up to 1 decimal place i.e., "0.9". I want to display "0.9000".

Here is my code:

float x2 = 0; 
decimal l = 0;
l =Convert.ToDecimal(Math.Round( (9 / 10.0) +(x2 / 10.0),4));
Console.WriteLine(l);
Arturo Menchaca
  • 15,783
  • 1
  • 29
  • 53
Bushra
  • 3
  • 2
  • try `Console.WriteLine("{0:F4}", l);` – Arturo Menchaca Apr 01 '16 at 16:47
  • Try using google or stack overflow search before wasting peoples time. For example, you can search on "C# format decimal with 4 decimal places" or "c# format number 4 decimal places". Both give valid answers within the first few results. Learning to use Google and other internet searches is key to becoming a successful software engineer. Nobody can know or remember everything. – komma8.komma1 Apr 02 '16 at 15:52

1 Answers1

1

Take a look at this Post

Display Float as String with at Least 1 Decimal Place

This should answer your question

Community
  • 1
  • 1
Fl3x1t
  • 21
  • 2
  • Link-only answers are not good, since links tend to die. Provide context for the link in your answer, please. – mbomb007 Apr 01 '16 at 16:54