You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using UnitsNet.Duration.FromSeconds(1).Nanoseconds produces 999999999.9999999 which not precise compared to other similar down scaled conversions for duration e.g. ms, µs.
To Reproduce
Steps to reproduce the behavior:
Add nuget UnitsNet 5.60.0 to a .NET 8.0 project
Build using Visual Studio 2022 Community v17.12.1
In a ConsoleApp write UnitsNet.Duration.FromSeconds(1).Nanoseconds to the console
Expected behavior
Nanoseconds produced from converting from seconds should produce 1000000000 rather than losing precision
Screenshots
Additional context
The normal TimeSpan (TimeSpan.FromSeconds(1).TotalNanoseconds) contains a more accurate nanoseconds
The text was updated successfully, but these errors were encountered:
this is a known limitation of the current implementation: having a double as the underlying value type, the conversions often introduce a small rounding error. Here's a quote that we should have probably added to the wiki page long ago:
Hopefully this won't be required with my upcoming proposition for replacing the doubles (the PR should be out this weekend).
Until such version is release, you should consider using ToString directly on the Duration itself, this should round-off the problem (you can specify the precision using the format specifier: e.g. "G4")
Describe the bug
Using
UnitsNet.Duration.FromSeconds(1).Nanoseconds
produces999999999.9999999
which not precise compared to other similar down scaled conversions for duration e.g. ms, µs.To Reproduce
Steps to reproduce the behavior:
UnitsNet.Duration.FromSeconds(1).Nanoseconds
to the consoleExpected behavior
Nanoseconds produced from converting from seconds should produce
1000000000
rather than losing precisionScreenshots
Additional context
The normal TimeSpan (
TimeSpan.FromSeconds(1).TotalNanoseconds
) contains a more accurate nanosecondsThe text was updated successfully, but these errors were encountered: