I hava 2 Double variables, and when I sum them it return me int variable. but I want it return Double too. What should I do? Thank you!
example:
double d = 4.0;
double Myd = 4.0;
Console.WriteLine ( d+Myd ); // it returns me 8 but I want 8.0 .
The value 8 and 8.0 are the same. If you want decimals shown in your results, use a converter like N2 for fixed with 2 SigDig after the decimal.
Console.WriteLine((d+Myd).ToString("N2"));
Shannon is corret. it is returning a double, but because it is all 0's after the decimal it cuts it off. if you were to do 8.5 + 8 it would return 16.5. If you require one decimal, just use an N1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.