swift - Calculate average pace -
i need convert decimal hour in hh:mm:ss display average pace walking app.
i have converted time decimal , have calculated pace in decimal unsure how convert time.
my timedecimal is:
let timedecimal:double = (hoursource + (minutesource / 60) + (secondsource / 3600)) / distancesource which gives me 0.4375
0 = 0 .4375 * 60 = 26.25 .25 = * 60 = 15 i know time should 00:26:15 not sure formula achieve without splitting result , performing multiplication multiple times.
any appreciated.
let formatter = nsdatecomponentsformatter() formatter.allowedunits = [ .hour, .minute, .second ] formatter.unitsstyle = .positional formatter.zeroformattingbehavior = .pad let string = formatter.stringfromtimeinterval(0.4375 * 3600)! result: 0:26:15.
Comments
Post a Comment