Skip to content

Instantly share code, notes, and snippets.

@chewbranca
Last active December 19, 2015 18:59
Show Gist options
  • Save chewbranca/6003085 to your computer and use it in GitHub Desktop.
Save chewbranca/6003085 to your computer and use it in GitHub Desktop.
var floatToArray = function(f, n) {
n = n || 3;
var p = Math.pow(10, n-1);
f = Math.round(f * p) / p;
var r = [];
for (var i = z = 0; i < n; i++) {
z *= 10;
r.push(parseInt(f * Math.pow(10, i)) - z);
z += r[i];
}
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment