Calculator in Flash (action Script 2.0)

Cool Buddy

Wise Old Owl
I am making a calculator in flash. I am able to design the basic interface & all the basic functions. But now i figured out that if I have say "2.1" displayed and I press the "." button, it becomes "2.1.". how to prevent this, Can anyone help?

Now, i figured out there are multiple ways in which a calculator can be made in flash. So i am giving an idea of how the numbers are displayed in my program

first I check if a calculation is to be performed
if yes
  • I first check if dot is displayed, if yes the number gets added as a string to the number already displayed
  • then I check if the number displayed is 0, if yes then the number pressed is displayed
  • if both of the above are false, the number is added as a string to the number already displayed.
if a calculation is to be performed
  • then the number pressed is displayed
function putnum(i) {
if (disp_num.length == 10 && calc == 0) { //checks the length, 10 digit calculator
}
else {
if (calc == 0) { //calc==0 means no calculation is to be performed
if (disp_num == "0.") { //if dot (.) button has been pressed
disp_num += ""+i;
} else if (disp_num == 0) { //if 0 is displayed
disp_num = i;
} else { //in all other cases, i.e. if 1, 12 or any other number is displayed
disp_num += "" + i;
}
}
else //if calculation is to be performed, i.e. say last button pressed is +
{
disp_num = i;
calc1 = calc;
calc = 0;
}
}
}

I figured out I can use indexOf function to find if the box already contains a dot (.), but I am not able to use the function properly, please help. It is returning undefined if the box contains a single digit number, in any other case, it is working fine
 
Top Bottom