Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
How to multiply timestring and float in ojbective c.

for e.g. timestring is 2:00 hour and float value is 1.5. How to multiply these two values and get the answer like this 3:00hous

Thanks in advance.
Posted

1 solution

Convert the time string to minutes as a float: 2 * 60 + 0 == 120.0
Multiply by the original float: 120.0 * 1.5 == 180.0
Convert this to an integer: 180.0 == 180
Take the modulus base 60 (this is the minutes): 180 % 60 == 0
Integer divide the value by 60 (this is the hours): 180 / 60 == 3
Convert the two values back to a string, remembering the leading zeros on the minutes and the colon.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900