+ 1

If give a value in int or float or double like double 10/3 then return the value 3.3 bt return 3 and same as float and int why?

4th Sep 2016, 6:20 PM
Akash Verma
Akash Verma - avatar
4 Answers
+ 1
you try type conversion, for example; double=x; x = (double)10/3; I hope i could help you
5th Sep 2016, 2:08 PM
sevgi
sevgi - avatar
+ 1
If you used a variable of type double or float it would return it with its decimals. When using integer type variables c# truncates the answer of an equation so the entire back end after the decimal point is discarded.
9th Sep 2016, 9:32 PM
Jason Badenhorst
Jason Badenhorst - avatar
0
If I understand your question you perform an integer division, resulting in another integer and thus truncating the fractional part. Try this to obtain the result as a real number: double x = 10 / 3.0;
4th Sep 2016, 10:47 PM
René Schindhelm
René Schindhelm - avatar
- 2
okkk thanku
5th Sep 2016, 1:44 AM
Akash Verma
Akash Verma - avatar