I am trying to make a calculator of sorts where you perform an operation and the code returns an answer that follows the rules of significant figures. Here is a boiled down portion of what I have coded:
var x = 0.002.toString().split(""); //to convert the number to a list
for(i = 0; i <= x.length; i++) {
if(x[i] != 0 || ".") {
x.splice(0, i);
{ break; }
}
}
The for loop is supposed to delete all of the non-significant 0's at the beginning, but it isn't working and I don't know what the problem could be.