Skip to content

DurationFormat introduces error in fractional digits #6462

@austinw-fineart

Description

@austinw-fineart

Which package?

@formatjs/intl-durationformat

Describe the bug

DurationFormat introduces what appears to be a floating precision error when given specific durations. What it appears to be doing under the hood is the equivalent of second + millisecond, and indeed any such numbers that produce the same floating precision error in JS such as 1 + .118 show up with the same error. However, since duration units are given in whole numbers there should be no reason to introduce floating arithmetic, and consequently floating error, into formatting.

To Reproduce

https://jsfiddle.net/chsk6t42/

Reproducible Steps/Repo

Steps to reproduce the behavior:

new DurationFormat('en', {
  milliseconds: 'numeric',
  style: 'narrow',
}).format({ milliseconds: 473, seconds: 1 });

Outputs the following: 1.472999999s

Expected behavior

Intl.DurationFormat on Chrome 147 outputs: 1.473s

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • Version: 147

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions