mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 12:38:06 +00:00
Refactor: Enhance ToString method for TValue struct to handle special double values
This commit is contained in:
@@ -26,5 +26,15 @@ public readonly record struct TValue(long Time, double Value)
|
|||||||
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
|
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
|
public override string ToString()
|
||||||
}
|
{
|
||||||
|
string valueStr = Value switch
|
||||||
|
{
|
||||||
|
double.PositiveInfinity => ((char)0x221E).ToString(),
|
||||||
|
double.NegativeInfinity => "-" + (char)0x221E,
|
||||||
|
_ when double.IsNaN(Value) => "NaN",
|
||||||
|
_ => Value.ToString("F2")
|
||||||
|
};
|
||||||
|
return $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {valueStr}]";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user