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 ?

Community
  • 1
  • 1
user1743553
  • 97
  • 1
  • 6
  • http://stackoverflow.com/questions/2129804/rounding-double-values-in-c-sharp and many others have good examples of how you can round in the .Net framework – dash Oct 18 '12 at 20:18

2 Answers2

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);
adripanico
  • 1,026
  • 14
  • 32
2

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

var x = Math.Round(56.365989365, 2);
System Down
  • 6,192
  • 1
  • 30
  • 34