core.time Duration how to get units in double/float format?

biozic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 17 10:57:13 PST 2016


On Sunday, 17 January 2016 at 14:43:26 UTC, Borislav Kosharov 
wrote:
> Seeing that TickDuration is being deprecated and that I should 
> use Duration instead, I faced a problem. I need to get total 
> seconds like a float. Using .total!"seconds" returns a long and 
> if the duration is less than 1 second I get 0. My question is 
> whats the right way to do it. Because I saw that TickDuration 
> has a to!("seconds", float) method, but Duration doesn't have 
> one. I can convert Duration to TickDuration and call to but 
> seeing that its deprecated makes me think there is a better way.

Why not just use a smaller granularity for Duration.total and 
convert the result?

duration.total!"nsecs" / cast(float) 1e9




More information about the Digitalmars-d-learn mailing list