Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

to 4 decimal points

Contributor ,
Nov 22, 2006 Nov 22, 2006
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.
TOPICS
ActionScript
4.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2006 Nov 28, 2006
post a link to your fla.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 28, 2006 Nov 28, 2006
yeah sorry i was going to do that but our network here was mucking up

ok here it is http://home.exetel.com.au/twistedpancreas/images/test7.fla
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 28, 2006 Nov 28, 2006
actually i've updated my file to resemble how the setup will work

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

i now have input3 as iodine and it's now giving me an answer but i think it's stuck on trying to round the number down to 3 significant figures (ie 0.0210), thus the answer will always be incorrect at the moment

any help would be most appreciated
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2006 Nov 29, 2006
try:

www.gladstien.com/new/test.fla
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2006 Nov 29, 2006
thanks kglad that's the ticket!

it's all now making a little more sense, although i've still got to get my head around some of the code (but big thanks to all who helped out)

my latest file is now http://home.exetel.com.au/twistedpancreas/images/test9.fla

got one small additional question (and maybe it should be a new topic), but is there anyway for the first check button to check for all numbers within the random range of numbers and return them as the correct answer if typed into titration.text (ie titrationValue = any result within the range of 0.02050 to 0.02080)?

i hope that makes sense
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2006 Nov 29, 2006
you're welcome.

you can check:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2006 Nov 29, 2006
you are a living legend kglad and you get my favourite person of the day :D

thanks a million!!!

my knowledge is slowly building, and a lot of it is due to this forum, thx all!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2006 Nov 29, 2006
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 2006
sorry to bring this one up again, but my client is now wanting this code to end up with no decimal point, ie if the answer was 446.5, then they'd want the answer as 447, and i'm a bit frazzled as to what to do, here is my code at the moment...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2006 Dec 18, 2006
> sorry to bring this one up again, but my client is now wanting this code
> to end
> up with no decimal point, ie if the answer was 446.5, then they'd want the
> answer as 447, here is my code at the moment...

That is SO much simpler .. just use Math.round

var multiNum:Number = 723699;
this.iodine = (Number(molInput.text)*Number(titrationInput.text))*multiNum;
this.iodine = Math.round(this.iodine);
trace(this.iodine)
this.titrationDisplay.text = this.iodine;
--
Jeckyl


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 2006
um i'm getting NaN when molInput.text = 0.0391 and titrationInput.text = 0.01630
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 2006
isn't iodine being defined twice there?

shouldn't it be something like

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2006 Dec 18, 2006
> isn't iodine being defined twice there?

No its fine


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2006 Dec 18, 2006
> um i'm getting NaN when molInput.text = 0.0391 and titrationInput.text =
> 0.01630

Then there is something going on you're not telling us, as the script will
work with those inputs .. are you sure there.s not other characters in the
strings?
--
Jeckyl


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 2006
yeah could be (knowing me)

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

it's got me stumped!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2006 Dec 18, 2006
just use Math.round() on your answer.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2006 Dec 18, 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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2006 Dec 18, 2006
don't use multiline textfields.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 18, 2006 Dec 18, 2006
doh!!!

thanks kglad and jeckyl

why do multiline textfields stuff it up?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2006 Dec 18, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 19, 2006 Dec 19, 2006
ah ok, but generally Flash just dislikes multiline textfields?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2006 Dec 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2006 Dec 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines