Fixes #380 - rounding fractions to a whole number.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 9 Nov 2014 16:54:39 +0000 (16:54 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 9 Nov 2014 17:05:53 +0000 (17:05 +0000)
History.md
lib/selectors/optimizers/simple.js
test/integration-test.js

index e725c51..ae880d0 100644 (file)
 * Fixed issue [#360](https://github.com/GoalSmashers/clean-css/issues/360) - adds 7 extra CSS colors.
 * Fixed issue [#363](https://github.com/GoalSmashers/clean-css/issues/363) - `rem` units overriding `px`.
 
+[2.2.17 / 2014-11-09](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.16...v2.2.17)
+==================
+
+* Fixed issue [#380](https://github.com/GoalSmashers/clean-css/issues/380) - rounding fractions to a whole number.
+
 [2.2.16 / 2014-09-16](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.15...v2.2.16)
 ==================
 
index 511cc56..5d1a988 100644 (file)
@@ -109,9 +109,13 @@ function precisionMinifier(_, value, precisionOptions) {
   return value
     .replace(precisionOptions.regexp, function(match, decimalPlaces) {
       var newFraction = Math.round(parseFloat('.' + decimalPlaces) * precisionOptions.multiplier) / precisionOptions.multiplier;
-      return precisionOptions.value === 0 || newFraction === 0 ?
-        'px' :
-        '.' + ('' + newFraction).substring('0.'.length) + 'px';
+      if (precisionOptions.value === 0 || newFraction === 0) {
+        return 'px';
+      } else {
+        return newFraction < 1 ?
+          '.' + ('' + newFraction).substring('0.'.length) + 'px' :
+          newFraction + 'px';
+      }
     })
     .replace(/(\d)\.($|\D)/g, '$1$2');
 }
index 4eb706a..f3f0270 100644 (file)
@@ -622,7 +622,11 @@ vows.describe('integration tests').addBatch({
     ],
     'do not round 2nd decimal place pixels': 'div{transform:translateY(20.55px)}',
     'do not round percentages': 'div{left:20.505%}',
-    'do not round ems': 'div{font-size:1.505em}'
+    'do not round ems': 'div{font-size:1.505em}',
+    'rounds .9999 correctly': [
+      'a{stroke-width:.99999px}',
+      'a{stroke-width:1px}'
+    ]
   }),
   'floats custom rounding': cssContext({
     'rounds to 4 values': [