Created
July 20, 2011 18:58
-
-
Save futuraprime/1095648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* sigdig | |
* | |
* rounds the number to a specified number of significant digits | |
*/ | |
['sigdig', false, function(setting, data) { | |
if (typeof data[1] == "number") { | |
var num_store = data[1], | |
order = Math.ceil(Math.log( num_store )/Math.log(10)), // get order of magnitude from log10 | |
n_down = num_store/Math.pow(10, order); // drop down | |
// now round, as above | |
n_down = n_down * Math.pow( 10, setting ); // bring the decimal down for rounding | |
n_down = Math.round(n_down); | |
n_down = n_down / Math.pow( 10, setting ); // and back. | |
//finally, undo the original transform | |
data[1] = n_down * Math.pow( 10, order ); | |
} | |
return data; | |
}], //sigdig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment