#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# How to convert decimal places to minutes...

Hi Everyone,

I am using Harlowe and would like to know how I can convert a number with decimal places into hours and minutes.

For example, I have the number 15.833333333333334 which would represent 15 hours and 50 minutes. Note that the 50 minutes is a rounding of the result of the decimal places multiplied by 60.

This is important to me, because in my story, different actions and passages subtract different amounts of "minutes" and I would like to display the remaining minutes as hours and minutes.

At the moment, when I have 950 minutes left, if I divide it by 60, I get the number above with decimal places. And I don't know what code I need to use for Harlowe to multiply and round only the decimal places.

Any help with this would be appreciated. Sorry for my newbiness!

• Try the following:
```(set: \$amount to 950)
(set: \$hours to (floor: \$amount / 60))
(set: \$minutes to (\$amount % 60))

hours: (print: \$hours)
minutes: (print: \$minutes)
```
• Thank you!!
• Also, to set a "clock" using 24 hour time with the code above given by greyelf, you can use the following:
```(if: \$hours > 23)[(set: \$hours to \$hours - 24)]
(if: \$hours < 10)[0\$hours](else:)[\$hours]:(if: \$minutes < 10)[0\$minutes](else:)[\$minutes]
```

Just sharing that, as that is what I am using in my game, thanks to the help I got from greyelf!
• Hi again,

Since I am trying to move my story over to the sugarCube format (since it seems more versatile for what i want to achieve), I was wondering how to get the time thing to work.

The only part that I am having trouble with is the following:
```(set: \$hours to (floor: \$amount / 60))
```

In SugarCube, I can't get the "floor" part to work, nor know how to get it to round the resulting number.

I have this so far:
```<<set \$hours to (\$pTime / 60)>>
```

But that returns the number with the decimal places. I can't find the solution in any of the sugarCube documentation.

Any ideas?
• Nevermind, I found the answer, and it is by adding parseInt before the brackets.

So the final SugarCube code that works for me now is:
```<<set \$hours to parseInt(\$pTime / 60)>>
```
• You could also use the standard Javascript Math.floor method in SugarCube.

My above example modified for SugarCube:
```<<set \$amount to 950>>
<<set \$hours to Math.floor(\$amount / 60)>>
<<set \$minutes to (\$amount % 60)>>

hours: <<print \$hours>>
minutes: <<print \$minutes>>
```