Skip to content

Allow rounding option #62

Closed
Closed

Description

@MartijnCuppens

This option allows users to limit the default precision to what's defined in precision, but doesn't round the number if the rounded number isn't equal to the number itself. This may sound a bit vague, so let's demonstrate this with an example:

Let's assume you have configured precision: 5 and allowRounding: false:

  • calc(100% / 3) will output calc(100% / 3) because calc(100% / 3) != 33.33333%
  • calc(100% / 4) will output 25% because calc(100% / 4) == 25%

What's the advantage? We never have rounded numbers which can cause issues like twbs/bootstrap#27374 and we don't have expressions like calc(100% / 4) that can be simplified.

PR: #61

Activity

  1. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    /cc @MartijnCuppens problem still exists, can you provide codepen where 33.33333% !== calc(100% / 3), because browsers already do same

  2. MartijnCuppens commented on Mar 27, 2019

    @MartijnCuppens
    ContributorAuthor

    I guess this is what you are looking for: https://codepen.io/MartijnCuppens/pen/rREmxN?editors=1010 (For some resolutions the buttons do have the same width, but in many cases they don't)

  3. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    hm looks like we potentially can break code

  4. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    I think we need new option for this, also i think we should don't round calc(100% / 3) by default (it is unsafe).

  5. MartijnCuppens commented on Mar 27, 2019

    @MartijnCuppens
    ContributorAuthor

    #61 was about adding an option which can be disabled to keep calc when the rounded version is not the same as the original value. So by default it would have been the same.

  6. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    @MartijnCuppens 👍 Can you send a PR again? For next major version we set allowRounding: false by default because we potentially can break code, it is bad.

  7. XhmikosR commented on Mar 27, 2019

    @XhmikosR

    @evilebottnawi You can reopen the PR.

  8. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    @XhmikosR still need rebase

  9. XhmikosR commented on Mar 27, 2019

    @XhmikosR

    That is something @MartijnCuppens can do after you reopen it.

  10. MartijnCuppens commented on Mar 27, 2019

    @MartijnCuppens
    ContributorAuthor

    It's now rebased

  11. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    @MartijnCuppens What do you think about disable round by default as i describe above in next major?

  12. MartijnCuppens commented on Mar 27, 2019

    @MartijnCuppens
    ContributorAuthor

    @evilebottnawi, the true behaviour is the same as it is now (I described this in the PR description #61 (comment)). I could also call it disallowRounding and set it to false if that's clearer.

  13. alexander-akait commented on Mar 27, 2019

    @alexander-akait
    Collaborator

    @MartijnCuppens Maybe we can do better:

    - precision: false - disable precision
    - precision: 5 - 5 characters
    - precision: 'safe' - as you want in this issue
    

    ?

  14. MartijnCuppens commented on Mar 28, 2019

    @MartijnCuppens
    ContributorAuthor

    precision: 'safe' would still need some kind of precision. Lets say for some reason the generated value would be: 15.35153465435186437435513 (and this is the exact number, no numbers after the last 3). That's a pretty long number, probably something you don't want. This is why I split precision & allowRounding.

  15. added a commit that references this issue on Oct 1, 2026
    700fb9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions