Open
Description
Description
According to the official document TimeSpan.FromSeconds(Double):
Returns a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
But the actual output retained more digits than millisecond.
Reproduction Steps
double paceSpeedInSeconds = 1.5099;
Console.WriteLine(TimeSpan.FromSeconds(paceSpeedInSeconds));
Console.WriteLine(((int)TimeSpan.FromSeconds(paceSpeedInSeconds).TotalMilliseconds));
Expected behavior
Should output (accurate to the nearest millisecond):
00:00:01.5100000
1510
Actual behavior
Outputs:
00:00:01.5099000
1509
Regression?
This is a regression. On .NET Framework 4.8, the actual behavior is consistent with the document:
00:00:01.5100000
1510
Known Workarounds
double paceSpeedInSeconds = Math.Round(1.5099, 3);
Console.WriteLine(TimeSpan.FromSeconds(paceSpeedInSeconds));
Console.WriteLine(((int)TimeSpan.FromSeconds(paceSpeedInSeconds).TotalMilliseconds));
Outputs:
00:00:01.5100000
1510
Configuration
.NET Core 3.1, .NET 5.0, .NET 6.0 on Windows.
Other information
No response