Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a large number to hours and minutes

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Good evening Sir/Madam!!

If I have got a number, lets say, 340, and wants to convert it to hours and minutes, then how can I do it?
Mathematic is not my stronger side in programming!!

Thanks for any help!!
Martin!!
[sig]<p>Martin G Broman<br><a href=mailto:mgb_svea@hotmail.com>mgb_svea@hotmail.com</a><br><a href= > </a><br>DWS - Alpha Whitin Dead Wolf Society[/sig]
 
what's the unit of number?
suppose second then

hours = 340 / 3600 ;
minutes = 340 / 60 ;
or
340 / 3600 + 340 / 60 + 340 % 60;
^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^
hours minutes seconds

maybe it is not what you need! but i cannot understand it!

Ragards! [sig][/sig]
 


Maybe my post was confusing..?
What I wanted was to takeout now how many hours I can get from a number i.e. 340,
Much like 61 would give 1 hour and 1 minute….
Hope you understood it more this time...
[sig]<p>Martin G Broman<br><a href=mailto:mgb_svea@hotmail.com>mgb_svea@hotmail.com</a><br><a href= > </a><br>DWS - Alpha Whitin Dead Wolf Society[/sig]
 
then your unit is minute,
hours = 61 / 60; //1 hours
minutes = 61 % 60; //1 minute

Is it right or not?


Regards! [sig][/sig]
 
No! Sorry, it didn't work as i wished for!!
However I did somthing like below, and it works!!
take a look.....

float countM,countH;

countH=2;
countM=81;
countH+=(int)countM/60;
countM=60*((countM/60)-((int)countM/60));

this would give me
3 hours and 21 minutes!!

Thanks anyway!! [sig]<p>Martin G Broman<br><a href=mailto:mgb_svea@hotmail.com>mgb_svea@hotmail.com</a><br><a href= > </a><br>DWS - Alpha Whitin Dead Wolf Society[/sig]
 
Oh,sir
countM = 60*((countM/60)-((int)countM/60))
is equal to countM = countM % 60; // 81 % 60 = 21;

Donnot you think mod operation is simple?


Regards!



[sig][/sig]
 
I tried your way of doing it but BCB3 said no!!
It called som error......
Do I need to include anything!! [sig]<p>Martin G Broman<br><a href=mailto:mgb_svea@hotmail.com>mgb_svea@hotmail.com</a><br><a href= > </a><br>DWS - Alpha Whitin Dead Wolf Society[/sig]
 
What was the error? Maybe all you need to do is add a math library.
[sig]<p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top