0

Here below is the operations..

double d=4.0;
double dd=4.0;
double results=d+dd;

it gives at the time of execution

results => 8

Instead of

results => 8.0

I would like to get output like below

results => 8.0

Will anybody tell me how to get decimal value with zero's also

Girish
  • 3
  • 3
  • 1
    It depends on how you print the result (printing means transforming the double to a string) – Steve Nov 17 '16 at 09:13
  • 1
    You need to format the output yourself - the variable "result" is a double & can be printed with decimal point & as many zeroes as you want. https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx – PaulF Nov 17 '16 at 09:14
  • You might want to check at `String.Format()` [examples](http://www.csharp-examples.net/string-format-double/) – Martin Verjans Nov 17 '16 at 09:15

1 Answers1

0

You can use String format for desired output. like

    String.Format(((Math.Round(results) == results) ? "{0:0}" : "{0:0.00}"), results);