jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
967 stars 121 forks source link

milliseconds portion is formatted as "1,000" ? #130

Open mg1075 opened 5 years ago

mg1075 commented 5 years ago

What is going on here? Is there a fix or workaround? moment.duration(3.033333333, "minutes").format("H:mm:ss.SSS"); or moment.duration(3.033333333, "minutes").format("H:mm:ss.S");

...yield this result: "3:01.1,000"

And then to confuse the situation further, moment.duration(3.033333333, "minutes").format("H:mm:ss.SS"); ...yields: "3:01.10"

jsmreese commented 5 years ago

This is another floating point rounding issue and related to #121.

You'll want to use the precision option in this case:

moment.duration(3.033333333, "minutes").format("H:mm:ss", 1);
"3:02.0"

moment.duration(3.033333333, "minutes").format("H:mm:ss", 2);
"3:02.00"

moment.duration(3.033333333, "minutes").format("H:mm:ss", 3);
"3:02.000"