Duration to Decimal Total

Jonathan Levi catanscout at gmail.com
Wed Nov 6 19:13:46 UTC 2019


`core.time.Duration` has a `total` function for extracting the 
value withing the Duration.  `total` returns a whole number 
(`long`).  Is there a function that returns a decimal (`double` 
or `float`)?

I cannot find one in `core.time`.  How would I do it then?
I know I can get finer precision (say msecs) and then divide it 
to get a courser precision (say secs) but then I might loose some 
potential accuracy.  I could do nsecs but that could be finer 
than than the actual internal number and therefore cause extra 
calculation or end up truncating really large numbers.

I would think a function that this would be appropriate to belong 
in the module.  Am I missing it?  Or, how would you recommend 
calculating it?

tldr: I am looking for a function like `double as(string 
units)(Duration)`.


More information about the Digitalmars-d-learn mailing list