Truncate the time interval after two decimal places

I have a time interval, which is displayed as such: 7.43053333333333. My goal is to simply display it as 7.43.

How to truncate the second value after the decimal place. I tried using Math.Roundinstead of truncating, but it will just return7

+3
source share
4 answers

Just use Math.Round Method (Decimal, Int32)

double d = 7.43053333333333;
double ma = Math.Round(d, 2);
+7
source

Use Math.Roundand put the number of digits in a round

double roundedValue = Math.Round(7.43053333333333, 2);

You will return 7.43

+1
source

.

, 2 .

:

double d = 7.43053333333333;
String s = d.ToString("N2");
+1

Math.Round(),

Math.Round(7.43053333333333, 2);
0

All Articles