Skip to main content
Inspiring
November 23, 2006
Question

to 4 decimal points

  • November 23, 2006
  • 37 replies
  • 4805 views
Ok i'm lost, even though I've asked this before.

I've got my file here http://home.exetel.com.au/twistedpancreas/images/test1.fla , calculating an equation.

But once again I need the answer to be to 4 decimal points (ie like an answer of 0.0393), but for the life of me I can't get it to work.

I tried *100 / 100 but i'm just confusing myself.

Sorry for my lack of knowledge, but i appreciate the help.
This topic has been closed for replies.

37 replies

Inspiring
November 23, 2006
thanks kglad

last thing,

i'm now trying to get input3 as a stored variable, and then the user (who will have the equation) has to type in the final answer

but for some reason i must be using the wrong syntax cause im getting a NAN result, see http://home.exetel.com.au/twistedpancreas/images/test5.fla

kglad
Community Expert
November 23, 2006
i put comments that explain the various branch points in the code. but expanding on those comments:

1. flash inserts a leading 0 and decimal for any number less than one. so, in that branch the number (converted to a string) should have lenghth 2+DecimalPlaces.

2. if the number is greater than 1, it may or may not have a decimal. so, in that branch both possiblities are handled.

2a. it has a decimal. then you just need to ensure that there are DecimalPlaces number of digits after the decimal.

2b. it has no decimal. so append a decimal followed by DecimalPlaces number of zeros.
Inspiring
November 23, 2006
woah that works, but i'm blown away as to how :)

any chance of a small description or sould i just be happy with what i got off you kglad

thanks bigtime!
Inspiring
November 23, 2006
i've also tried

var my_str:String = input3.text;
trace(my_str.length); // output: 6

if (my_str != 6)

input3.text = input3.text + "0";

else
{
input3.text = input3.text;
}

but this just adds on 0's no matter what, hmm i'll keep on soldiering on unless you guys know a better way.
Inspiring
November 23, 2006
actually i will continue on with this question i had.

see http://home.exetel.com.au/twistedpancreas/images/test2.fla now

the problem i have now is that whenever a number comes up with a "0" at the end it drops it off. I've asked this before (see http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=288&threadid=1213289 ) but for some reason arunbe's code is throwing in double decimal points now.

What am i doing wrong?
kglad
Community Expert
November 23, 2006
if you want to see DecimalPlaces number of digits after a decimal point from roundToDecimalPlace() use:

Known Participant
August 5, 2010

Hi again Kglad!

I have an inquiry regarding integers in a similar piece of code you helped with earlier:

I have a basic counter using a dynamic text box named counterText to show:

var curcount:Number= 3.0;
var increment:Number = 0.1;

var si:Number = setInterval(function ()
{   
counterText.text = String(curcount += increment);

}, 200);

This works, except when the number is an integer.

What code do I need in AS 2 to get this to show 1 decimal point to right?

kglad
Community Expert
November 23, 2006
i don't think so. at least, i've never figured it out if there is a way.
Inspiring
November 23, 2006
actually ignore this post, i just worked it out

is there anyway to delete posts?