Copy link to clipboard
Copied
Hey Guys,
I am very new to flash and I have finished my calculator!
But when you put a decimal into the dynamic text, then it calculates without the decimal.
If you are confused, here is an example.
20 / 5.5 = 4
10 / 2.2 = 5
3.2 / 2 = 1.6
3.2 + 2 = 5
I really need help.
Regards,
Ivan
Copy link to clipboard
Copied
you can use the flash string methods to add periods and trailing zeros.
Copy link to clipboard
Copied
How can I do that?
Copy link to clipboard
Copied
pass formatF() the number you want formatted and the number of decimal places you want displayed
function formatF(n:Number,dec:uint):String {
Copy link to clipboard
Copied
So lets so in one of the two textboxes there is a decimal.
And the on with a decimal is anonymous, how would it be formatted?
And the number of Decimal places anonymous?
function formatF(n:text_input_2.text,dec:10):String {
var p:Number=Math.pow(10,dec);
var nS=String(Math.round(n*p)/p);
if (dec==0) {
return nS;
}
if (nS.indexOf(".")>-1) {
var a:Array=n.toString().split(".");
} else { var a:Array=[nS,"0"]; } while (a[1].length<dec) { a[1]=a[1]+"0"; } return a[0]+"."+a[1];}
Copy link to clipboard
Copied
I have 2 input textboxes
t1 and t2
and my code:
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.CLICK,fC);
function fC(evt:MouseEvent)
{
trace(Number(t1.text)/Number(t2.text));
}
and always get decimal
Copy link to clipboard
Copied
I do get a decimal when I divide 2 / 3.
0.666666666666666666666666
But when one of my textboxes = a decimal then I get a round.
8 * 4.5 = 36
What I get is 32.
8 + 1.5 = 9
Copy link to clipboard
Copied
show code please.
Copy link to clipboard
Copied
Well, is it necessary?
Copy link to clipboard
Copied
hh is trying to be helpful but doesn't understand the issue. use the code i suggested.
Copy link to clipboard
Copied
OK!!
Since I am new to flash, do you mind modifying it so that it shows the decimal of the operation between the two textboes?
Copy link to clipboard
Copied
copy and paste the code you're using that's related to those two textfields.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more