From: Jakub Pawlowicz Date: Sun, 9 Nov 2014 16:54:39 +0000 (+0000) Subject: Fixes #380 - rounding fractions to a whole number. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=cbf8a9aa0c898129215a1012cc195d88ab67eba7;p=clean-css.git Fixes #380 - rounding fractions to a whole number. --- diff --git a/History.md b/History.md index e725c519..ae880d0f 100644 --- a/History.md +++ b/History.md @@ -16,6 +16,11 @@ * 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) ================== diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index 511cc56f..5d1a9888 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -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'); } diff --git a/test/integration-test.js b/test/integration-test.js index 4eb706a5..f3f02706 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -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': [