ive got a dynamic text box… var name c…
and i got some maths in the as that then send the answer to the dynamic text box c…but i oftenget the chacaters getting cut off…
is there a wat to limit how many number are displayed useing as without rounding to whole numbers…i need to set a sertai amout of decimal places…thx…
it’s not that hard…
// prototype
Number.prototype.limitDecimals = function(decimals) {
var str, tmp = this.toString(), dIndex = tmp.lastIndexOf(".")+1, index;
for (index=0; index<dIndex+decimals; index++) str += tmp.charAt(index);
return str;
};
// usage
Number.limitDecimals(decimals);
// example
myNumber = 7.7777;
trace(myNumber.limitDecimals(2)); // output: 7.77
=)
forget about that… as usual, i like the hard way.
Number.prototype.limitDecimals = function(decimals) {
this = this.toString().substr(0, this.toString().lastIndexOf(".")+1+decimals);
return Number(this);
};
that’s much better. =)
theres also
Number.prototype.limitDecimals = function(depth) {
var factor = Math.pow(10,depth);
return Math.round(this*factor)/factor;
};
which rounds to that decimal and not just chops
interesting… why i didn’t think about that!?
wait!! i know the answer… i’m a rookie. :-\