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
This commit is contained in:
euzuro
2007-08-27 08:52:12 +00:00
parent ea31ec076b
commit 61a6171a63
+10 -5
View File
@@ -125,12 +125,17 @@ String.prototype.camelize = function() {
* If null, 0, or negative value passed in, returns 0 * If null, 0, or negative value passed in, returns 0
*/ */
Number.prototype.limitSigDigs = function(sig) { Number.prototype.limitSigDigs = function(sig) {
var number = (sig > 0) ? this.toString() : 0; var numStr = (sig > 0) ? this.toString() : "0";
if (sig < number.length) { if (numStr.contains(".")) {
var exp = number.length - sig; var msg = "limitSigDig can not be called on a floating point number";
number = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp); 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);
} }