I'd like to convert Float to X hours XX minutes or less in Javacript.

Asked 2 years ago, Updated 2 years ago, 46 views

I'd like to convert Float to X hours XX minutes or less in Javacript.
1.2=>"1 hour and 12 minutes"
1.211=>"1 hour and 12 minutes"
1.11=>"1 hour 06 minutes"
1.8=>"1 hour 48 minutes"
1.89=>"1 hour 53 minutes"

Does such a library exist?
Or do I need to implement it myself?

javascript

2022-09-29 22:45

1 Answers

Suppose the variable f contains such a value.

`${Math.floor(f)} hours ${(Math.floor(f*60)%60).toString().padStart(2,'0')} minutes`

I think it's okay to do that.


2022-09-29 22:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.