From 61a6171a63636e0934e0715fbb8c471e9f9096a3 Mon Sep 17 00:00:00 2001 From: euzuro Date: Mon, 27 Aug 2007 08:52:12 +0000 Subject: [PATCH] calling limitSigDigs() on a floater now raises an error. console console (Closes #862) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4046 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index b5735b8f0d..120b7c03d4 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -125,12 +125,17 @@ String.prototype.camelize = function() { * If null, 0, or negative value passed in, returns 0 */ Number.prototype.limitSigDigs = function(sig) { - var number = (sig > 0) ? this.toString() : 0; - if (sig < number.length) { - var exp = number.length - sig; - number = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp); + var numStr = (sig > 0) ? this.toString() : "0"; + if (numStr.contains(".")) { + var msg = "limitSigDig can not be called on a floating point number"; + OpenLayers.Console.error(msg); + return null; } - return parseInt(number); + if ( (sig > 0) && (sig < numStr.length) ) { + var exp = numStr.length - sig; + numStr = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp); + } + return parseInt(numStr); }