I have very stupid issue i am simply taking input of on double and adding it to other double which is already declared and assign a value but sum is not showing floating point
double d = 4.0;
// Getting second double from user
double numDouble = Double.Parse(Console.ReadLine());
//Printing double number :
Console.WriteLine(d + numDouble);
result is always 4.0 + 2.0 = 6
but i want 6.0
any idea
When you double a number, the answer is always even. Example 1 => To double 13 => Firstly, partition 13 => 10 and 3.
To get a double of a number, we add the same number to itself. For example, double of 2 is 2 + 2 = 4.
Double of 12 = 12 + 12 = 24.
Math says, that
6 = 6.0 = 6.00 = 6.000 = ...
so what you want is a representation of double
value as a string
:
// F1: - one digit after decimal point
Console.WriteLine((d + numDouble).ToString("F1"));
Console.WriteLine("{0:F1}", d + numDouble);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With