# Thread: Converting mins into seconds?

1. ## Converting mins into seconds?

Code:
``` double baking=.5*(45)+45;

double baking_seconds=```

In the above example, the top variable would give 67.5 minutes.

How do i write a code such that it'll show 67 mins and 30 seconds?

Thanks

2. Extract the integer and fractional parts.
modf(3) - Linux man page

Or do x - (int)x to get the fraction.

Or do the whole thing as integer seconds, then use /60 and %60 to get minutes and seconds.

Or.....

3. Perhaps you can use two ints: seconds and minutes. Do all timing calculations in terms of seconds, and to convert to minutes and seconds, while seconds > 60, subtract 60 and increment minutes.

4. Originally Posted by Salem
Extract the integer and fractional parts.
modf(3) - Linux man page

Or do x - (int)x to get the fraction.

Or do the whole thing as integer seconds, then use /60 and %60 to get minutes and seconds.

Or.....
would modulo sign work in this case?
67.5%60= .5?

Or do the whole thing as integer seconds, then use /60 and %60 to get minutes and seconds.
And if you have a compiler at your disposal, why not just try it and see what happens?

6. Originally Posted by tmac619619
would modulo sign work in this case?
67.5%60= .5?
No, actually it would not because you cant use the modulus operator with floats.
Even if it did work, that mathematical calculation would give you 7.5.
You didn't think that through well.

7. There would be a way to use modulo, though, right?

8. Originally Posted by gratiafide
There would be a way to use modulo, though, right?
This is one way:

double baking=67.5
int temp = baking //get the int part of baking
seconds = temp * 3600 //and convert them to seconds

//handle fractional hours to seconds
temp = (baking * 100)*0.6 //calculate seconds from fractional part of baking,

and add them to the seconds from the int part
seconds+=temp; //no fractional part doesn't cause an error

print up seconds