Open EddyHaigh opened 2 days ago
Hi @EddyHaigh,
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:
The double data type in C# uses a binary floating-point representation, which complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.
Hopefully this won't be required with my upcoming proposition for replacing the double
s (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 nanoseconds