Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get short value using Double Function? [duplicate]

Tags:

c#

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 ?

like image 573
user1743553 Avatar asked Oct 20 '25 06:10

user1743553


2 Answers

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);
like image 198
adripanico Avatar answered Oct 22 '25 21:10

adripanico


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

var x = Math.Round(56.365989365, 2);
like image 32
System Down Avatar answered Oct 22 '25 20:10

System Down



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!