I am using the code
var minutesPassed = (DateTime.UtcNow - conversionsList.Last().DateStamp).TotalMinutes;
to calculate how much minutes passed between two dates. The result which I get looks like
254.54445556
I get minutes and seconds. How to get result which would contain only minutes like this
254
?
Just explicitly convert the result to int
:
var minutesPassed = (int)(DateTime.UtcNow - conversionsList.Last().DateStamp).TotalMinutes;
Use Math.Floor()
to convert 254.xxxx to 254:
var minutesPassed = Math.Floor((DateTime.UtcNow - conversionsList.Last().DateStamp).TotalMinutes);
You can just get the int part
int minutes = (int) (DateTime.UtcNow - conversionsList.Last().DateStamp).TotalMinutes;
this will get you the int part of the value.
EDIT: as far as rounding of value is considered. That is not true. Consider the following:
double d = 254.99999999999d;
int test = (int)d;
Here test
will hold 254
, not 255
The only problem with the explicit cast is OverFlowException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With