4

Possible Duplicate:
Create Excel (.XLS and .XLSX) file from C#
Rounding double values in C#

my double function generating values like this

  56,365989365

i want just value like this 56,36 how to get this ?

1

2 Answers 2

8

If you want to trucate the value:

value *= 100;
value = Math.Truncate(value);
value /= 100;

If you want to round the value:

value = Math.round(value, 2);
1
  • 1
    +1 from me for spotting the truncate.
    – dash
    Commented Oct 18, 2012 at 20:28
2

Use Math.Round. The second argument is the number of places.

var x = Math.Round(56.365989365, 2);

Not the answer you're looking for? Browse other questions tagged or ask your own question.