Skip to content

[css-values-4] What is the unit of round(A, B) if A and B have different units? #12690

@mkrause

Description

@mkrause

In the expression round(2rem, 1px), what would be the unit of the resulting length? Is it even defined?

Here are some test cases: https://codepen.io/maikelkrause/pen/yyBxJPg

The codepen above gives different results (for test case 2 and 3) in all three major browsers. (Note: I assumed that Chrome's implementation is the correct one so those are marked as "passing", but this is what I want to double check in this issue.) It uses tan(atan2()) to extract the scalar part of a dimensional value.

  • Chrome 139: (1) 32px, (2) 32px, (3) 32px
  • Firefox 142: (1) 31.9999px, (2) 31.9999px, (3) 0px
  • Safari 18.6: (1) 32px, (2) 0.250549px, (3) 0.250549px

From the spec:

The round(<rounding-strategy>?, A, B?) function contains an optional rounding strategy, and two calculations A and B, and returns the value of A, rounded according to the rounding strategy, to the nearest integer multiple of B either above or below A. The argument calculations can resolve to any <number>, <dimension>, or <percentage>, but must have a consistent type or else the function is invalid; the result’s type will be the consistent type.

If A is exactly equal to an integer multiple of B, round() resolves to A exactly

The spec mentions that the result may be (1) the nearest integer multiple of B (implies the unit of B?), or (2) A exactly (implies the unit of A?).

(This may be related to #7482.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-values-4Current Work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions