Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rounding option #61

Open
wants to merge 1 commit into
base: master
from

Conversation

@MartijnCuppens
Copy link
Contributor

@MartijnCuppens MartijnCuppens commented Oct 26, 2018

allowRounding (default: true)

With this variable set true, calc(100% / 3) will output 33.33333% (with precision: 5). If it is set false it will remain calc(100% / 3).
Another example with allowRounding: false: calc(900% / 16) will output 56.25% with precision: 5 (because calc(900% / 16) == 56.25%), but calc(900% / 16) with precision: 0 (because calc(900% / 16) != 56%).

By default this option is true and this will result in the same behaviour as we have now. If it's set to false, we prevent for example calc(100% / 3) to be rounded to 33.33333%.

Closes #62

@andyjansson
Copy link
Contributor

@andyjansson andyjansson commented Oct 27, 2018

There is no difference here from the current implementation. You can already disable rounding by setting precision to false.

@MartijnCuppens
Copy link
Contributor Author

@MartijnCuppens MartijnCuppens commented Oct 27, 2018

@andyjansson, there is a difference when the allowRounding is set false:

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.

This option is a bit tricky because it depends on another option, that's why I tried to explain it with examples instead of words.

@andyjansson
Copy link
Contributor

@andyjansson andyjansson commented Oct 27, 2018

Please open an issue about it so it can be discussed further.

@MartijnCuppens MartijnCuppens force-pushed the MartijnCuppens:allow-rounding branch from 83becf4 to 2773092 Mar 27, 2019
@@ -116,6 +116,19 @@ var out = postcss()
.css
```

#### `allowRounding` (default: `true`)

With this variable set `true`, `calc(100% / 3)` will output `33.33333%` (with `precision: 5`). If it is set `false` it will remain `calc(100% / 3)`.

This comment has been minimized.

@XhmikosR

XhmikosR Mar 27, 2019

set to x2 :)

@evilebottnawi
Copy link
Collaborator

@evilebottnawi evilebottnawi commented Apr 3, 2019

/cc @MartijnCuppens can we rebase again? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.