Skip to main content
Inspiring
November 23, 2006
Question

to 4 decimal points

  • November 23, 2006
  • 37 replies
  • 4828 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

Participant
December 20, 2006
I was reading this thread and made a class of your decimal function

class com.joshspoon.utils.Mathtilies
{

public function Mathtilies ()
{


}
public static function decimalPlaces (NumbertoConvert, DecimalPlaces) : Number
{
NumbertoConvert = NumbertoConvert;
DecimalPlaces = DecimalPlaces;
var input3 = Math.pow (10, DecimalPlaces);
var numericVal = Math.round (NumbertoConvert * input3) / input3;
var stringVal = "" + numericVal;
if (numericVal < 1)
{
// length should be 2+DecimalPlaces
while (stringVal.length < 2 + DecimalPlaces)
{
stringVal = stringVal + "0";
}
} else
{
// should have DecimalPlaces digits after the decimal, if there is a decimal
var decimalPos = stringVal.indexOf (".");
if (decimalPos > - 1)
{
// has a decimal
while (stringVal.charAt (decimalPos + DecimalPlaces) == "")
{
stringVal = stringVal + "0";
}
} else
{
// no decimal
stringVal = stringVal + "." + (input3 + "").substring (1);
}
}
return stringVal;
}
}

If any one want it.
kglad
Community Expert
Community Expert
December 19, 2006
no, not at all. it just depends upon your needs.

but if you want to input a number, it doesn't make sense to use a mulitline textfield.
Inspiring
December 19, 2006
ah ok, but generally Flash just dislikes multiline textfields?
kglad
Community Expert
Community Expert
December 19, 2006
you're welcome.

actually, it's your letterspacing being non-zero incombination with the textfield being multiline that causes flash to add a carriage return.
Inspiring
December 19, 2006
doh!!!

thanks kglad and jeckyl

why do multiline textfields stuff it up?
kglad
Community Expert
Community Expert
December 19, 2006
don't use multiline textfields.
Inspiring
December 19, 2006
ok thanks kglad,

that worked on my original code, but how come it's not working on http://home.exetel.com.au/twistedpancreas/roundingNumbersTest.fla

ie, Jeckyl's code
Inspiring
December 19, 2006
If you look at your trace output, you'll see they have extra newlines at the
end.

That's because you've made the input text boxes multi-line .. they should be
single-line

Pretty obvious really .. once you see it.
--
Jeckyl


kglad
Community Expert
Community Expert
December 19, 2006
just use Math.round() on your answer.
Inspiring
December 19, 2006
yeah could be (knowing me)

here's my file: http://home.exetel.com.au/twistedpancreas/roundingNumbersTest.fla

it's got me stumped!