Skip to content

Commit 62c4a50

Browse files
committed
5 decimals rounding for everything
1 parent e7a8eb7 commit 62c4a50

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# 1.1.4 - 2014-11-12
2+
3+
* 5 decimals rounding for everything
4+
15
# 1.1.3 - 2014-08-13
26

3-
* 5 decimals rounding
7+
* 5 decimals rounding for percentage
48

59
# 1.1.2 - 2014-08-10
610

index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ function evaluateExpression (expression, functionIdentifier, call) {
8181
// Transform back to a percentage result:
8282
if (unit === "%") {
8383
result *= 100
84-
85-
// adjust rounding shit
86-
// (0.1 * 0.2 === 0.020000000000000004)
87-
result = Math.round(result * DECIMAL_PRECISION) / DECIMAL_PRECISION
8884
}
8985

86+
// adjust rounding shit
87+
// (0.1 * 0.2 === 0.020000000000000004)
88+
result = Math.round(result * DECIMAL_PRECISION) / DECIMAL_PRECISION
89+
9090
// We don't need units for zero values...
9191
if (result !== 0) {
9292
result += unit

test/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ test("reduce prefixed css calc()", function(t) {
7474

7575
test("handle rounding issues", function(t) {
7676
t.equal(reduceCSSCalc("calc(10% * 20%)"), "2%", "should round percentage")
77+
t.equal(reduceCSSCalc("calc(3rem * 1.2)"), "3.6rem", "should round floats")
7778
t.end()
7879
})
7980

0 commit comments

Comments
 (0)