On Tuesday, 19 February 2019 at 14:34:09 UTC, drug wrote:
Now I do it this way (https://run.dlang.io/is/8kVibT):
```
auto some_duration = dur!"msecs"(500);
auto seconds = some_duration.total!"hnsecs" / 10_000_000.0;
assert(seconds.approxEqual(0.5));
```
is there better way to do it?
What you're doing now is the way to do it. This is by design, as
Jonathan M. Davis explains:
"In general, using floating point values with time is an
incredibly bad idea. It can certainly make sense when printing
stuff out, but using it in calculations is just asking for
trouble given all of the unnecessary imprecision that it adds.
So, Duration does not directly support floating point values at
all, and that's very much on purpose.
(...)
And if you're just trying to print out the a duration as a
floating point value, because it's nice to view that way, then
that's fine, but you'll need to do the conversion yourself. And
it's not that hard."
https://forum.dlang.org/post/[email protected]