What is a good data-type for saving hours in .net?
Is it better to use the decimal
type or is the double
data-type more appropriate. With hours I mean values such as:
A good way to represent a number of hours is to use a TimeSpan:
TimeSpan hours = TimeSpan.FromHours(2);
Given the choice between decimal
or double
I'd probably go for double
as there is typically no expectation that the amount of time is represented exactly. If you need an exact decimal representation of your fractional number of hours (which seems unlikely) then use decimal
.
You could also consider storing it as an integer in for example seconds, milliseconds or ticks.
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