Page 1 of 1

converting decimal to HH:MM:SS?

Posted: Sun Dec 16, 2007 7:46 pm
by iggy
hello everyone,

for school i got an assignment, wich stated we had to create a program in Quickbasic that would let you convert a decimal time (like 3,14 hours) to HH:MM:SS.

now i know how to do this on paper or in my head or what ever, but i have absolutly no clue how i should do this in quickbasic :?

does anyone have some pointers or tips for me?

any help is much appreciated!

thx in advance :wink:

Posted: Sun Dec 16, 2007 11:34 pm
by iggy
ive found it meself :D

Code: Select all

CLS
PRINT "Hallo, Met dit programma kun je Decimale tijden omrekenen naar UU:MM:SS"
INPUT "Voer een decimaal getal in alstublieft", getal!

uren = FIX(getal!)
switch1 = (60 * (getal - uren))
minuten = FIX(switch1)
switch2 = switch1 - minuten
seconden = FIX((switch2 * 60))
PRINT uren; ":"; minuten; ":"; seconden

Posted: Mon Dec 17, 2007 8:26 am
by Valerie
Hello Iggy & welcome to the forums.

Posted: Wed Dec 19, 2007 6:17 am
by Ralph
That's great, Iggy! Glad you found a program that does what you need. The program seems very clear and well done.

Now, PLEASE read the program and try to understand each and every line of it, as that is the only way that you will benefit from the program, believe me!

Then, if you have questions, folks here will be happy to help you out with good answers.

Posted: Thu Aug 07, 2008 11:09 am
by Dragoncat
this is assuming you are using seconds as the input or such..
here is another way:
create a blank string (empty ) to hold the desired output : tim$
like this tim$=""
split the number into separate parts:
hour%=seconds%/3600
min% = (seconds% mod 60)/60
sec =seconds% mod 60
then convert each to strings
tim$ =str$(hour%)+":"+str$(min%)+":"+str$(sec%)
something like that anyways...

Posted: Tue Oct 14, 2008 8:55 pm
by dziekan_tek
Dragoncat wrote: min% = (seconds% mod 60)/60
Everything's fine but here is a little mistake. It should be:

min% = (seconds% / 60) MOD 60

;-)
Cheers!