From 44e1190f824c8a5385a09742d509b7d18688e8bb Mon Sep 17 00:00:00 2001 From: Sam Fung Date: Fri, 4 Sep 2015 17:25:30 -0700 Subject: [PATCH] Using parseFloat() to calculate percentage to yield more precise result. --- js/angular/directive/collectionRepeat.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/js/angular/directive/collectionRepeat.js b/js/angular/directive/collectionRepeat.js index a5586396b2a..cc6f29240eb 100644 --- a/js/angular/directive/collectionRepeat.js +++ b/js/angular/directive/collectionRepeat.js @@ -338,17 +338,15 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r // If it's a constant, it's either a percent or just a constant pixel number. if (isConstant) { - var intValue = parseInt(parsedValue()); - // For percents, store the percent getter on .getValue() if (attrValue.indexOf('%') > -1) { - var decimalValue = intValue / 100; + var decimalValue = parseFloat(parsedValue()) / 100; dimensionData.getValue = dimensionData === heightData ? function() { return Math.floor(decimalValue * scrollView.__clientHeight); } : function() { return Math.floor(decimalValue * scrollView.__clientWidth); }; } else { // For static constants, just store the static constant. - dimensionData.value = intValue; + dimensionData.value = parseInt(parsedValue()); } } else { @@ -357,14 +355,14 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r function heightGetter(scope, locals) { var result = parsedValue(scope, locals); if (result.charAt && result.charAt(result.length - 1) === '%') { - return Math.floor(parseInt(result) / 100 * scrollView.__clientHeight); + return Math.floor(parseFloat(result) / 100 * scrollView.__clientHeight); } return parseInt(result); } : function widthGetter(scope, locals) { var result = parsedValue(scope, locals); if (result.charAt && result.charAt(result.length - 1) === '%') { - return Math.floor(parseInt(result) / 100 * scrollView.__clientWidth); + return Math.floor(parseFloat(result) / 100 * scrollView.__clientWidth); } return parseInt(result); };