# Time conversion confusion

• ### Question

• User-374939276 posted

If I convert 1025.1 to the format hh:mm:ss,ms there seems to be a weird issue.  The output is: 00:00:01,25.09999999999991

https://jsfiddle.net/warrenkc/wujLk5ap/1/

The output should be:  something like: 00:00:01,25.099

Monday, March 23, 2020 4:15 AM

• User-719153870 posted

Hi warrenkc2,

#### warrenkc2

The output should be:  something like: 00:00:01,25.099

I don't think it shall output 00:00:01,25.099, according to your code:

```function formatMilliseconds(milliseconds) {
var seconds = Math.floor(milliseconds / 1000) % 60;
var minutes = Math.floor(seconds / 60)  % 60;
var hours = Math.floor(minutes / 60);
var milliseconds = milliseconds % 1000;

}```

In general math, the milliseconds should be 25.1 after milliseconds % 1000, so the final output should be 00:00:01,25.1 or if you prefer 00:00:01,25.100.

To achieve this, you will need the toFixed() method.

`var milliseconds = (milliseconds % 1000).toFixed(1);`

or toFixed(3), choose whichever you like.

You can find more information about why it returns the wrong value at Is floating point math broken?

Best Regard,

Yang Shen

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Monday, March 23, 2020 6:01 AM

### All replies

• User-719153870 posted

Hi warrenkc2,

#### warrenkc2

The output should be:  something like: 00:00:01,25.099

I don't think it shall output 00:00:01,25.099, according to your code:

```function formatMilliseconds(milliseconds) {
var seconds = Math.floor(milliseconds / 1000) % 60;
var minutes = Math.floor(seconds / 60)  % 60;
var hours = Math.floor(minutes / 60);
var milliseconds = milliseconds % 1000;

}```

In general math, the milliseconds should be 25.1 after milliseconds % 1000, so the final output should be 00:00:01,25.1 or if you prefer 00:00:01,25.100.

To achieve this, you will need the toFixed() method.

`var milliseconds = (milliseconds % 1000).toFixed(1);`

or toFixed(3), choose whichever you like.

You can find more information about why it returns the wrong value at Is floating point math broken?

Best Regard,

Yang Shen

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Monday, March 23, 2020 6:01 AM
• User-374939276 posted

```function formatSeconds(totalSeconds) {