I have the following code :
double a = 8/ 3;
Response.Write(a);
It returns the value 2. Why? I need at least one decimal digit. Something like 2.6, or 2.66. How can I get such results?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
or
to get a precise answer.
Since in expression
a = 8/3both the operands areintso the result isintirrespective of the fact that it is being stored in adouble. The results are always in the higher data type of operandsEDIT
To answer
In case the values are coming from a variable you can cast one of the operands into
doublelike: