add limitSigDigs() function to number's prototype. tests included
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1008 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -707,6 +707,22 @@ Array.prototype.indexOf = function(element) {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {int} sig
|
||||
*
|
||||
* @returns The number, rounded to the specified number of significant digits.
|
||||
* If null, 0, or negaive value passed in, returns 0
|
||||
* @type int
|
||||
*/
|
||||
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);
|
||||
}
|
||||
return parseInt(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} id
|
||||
* @param {OpenLayers.Pixel} px
|
||||
|
||||
Reference in New Issue
Block a user