c# – Real numbers in c #


How to print the full value of a real number in c #?

The division of 21/60 = 0.35

In my C # code I have

int n1 = 21;
int n2 = 60;

double n3 = n1/n2;

Console.WriteLine("{0:00.0}", n3);  

I did it this way too

Console.Write(String.Format("{0:#.0}", n3));

In console it only prints 0.0 or .0 and I need the full value of decimal numbers, floats etc. such as 0.35 or o.75262


What you have to do is declare n1 and n2 as double as well

In the following way it will show you 0.35

 double n1 = 21;
 double n2 = 60;

 double n3 = n1 / n2;

Scroll to Top