Use this struct to generate rounded
TimeSpan values.
Namespace: CleanCode.DataAssembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
public struct RoundedTimeSpan
public struct RoundedTimeSpan
Public Structure RoundedTimeSpan
Public Structure RoundedTimeSpan
public value class RoundedTimeSpan
public value class RoundedTimeSpan
The standard TimeSpan struct renders like this:
Console.WriteLine(new TimeSpan(19365678)) => 00:00:01.9365678
Console.WriteLine(new TimeSpan(19365678)) => 00:00:01.9365678
A
RoundedTimeSpan struct, on the other hand, lets you adjust the precision:
Console.WriteLine(new RoundedTimeSpan(19365678, 5)) => 00:00:01.93657
Console.WriteLine(new RoundedTimeSpan(19365678, 3)) => 00:00:01.937
Console.WriteLine(new RoundedTimeSpan(19365678, 5)) => 00:00:01.93657
Console.WriteLine(new RoundedTimeSpan(19365678, 3)) => 00:00:01.937
Those values implicitly come from the default
ToString method.
There is an additional convenience method to generate a string with displayed digits different than the precision:
Console.WriteLine(new RoundedTimeSpan(19365678, 3).ToString(5)) => 00:00:01.93700
Console.WriteLine(new RoundedTimeSpan(19365678, 3).ToString(5)) => 00:00:01.93700
Be aware, however, that if the precision in your constructor is greater than
the length specified to display,
then
ToString(Int32) effectively is truncating rather than rounding.
Since CleanCode 0.9.31.