Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate Timespan after two decimal places

Tags:

c#

I have a timespan that displays as such: 7.43053333333333. My goal is to simply display it as 7.43.

How would I truncate two the second value after the decimal place. I tried using Math.Round instead of truncating, but it would simnple return 7

like image 442
Justin Adkins Avatar asked Dec 20 '22 17:12

Justin Adkins


1 Answers

Just use Math.Round Method (Decimal, Int32)

double d = 7.43053333333333;
double ma = Math.Round(d, 2);
like image 182
BRAHIM Kamel Avatar answered Dec 29 '22 12:12

BRAHIM Kamel