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

**Decimal Help**

New Here ,
Dec 23, 2010 Dec 23, 2010

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

TOPICS
ActionScript
1.1K
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 23, 2010 Dec 23, 2010

you can use the flash string methods to add periods and trailing zeros.

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 23, 2010 Dec 23, 2010

How can I do that?


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 23, 2010 Dec 23, 2010

pass formatF() the number you want formatted and the number of decimal places you want displayed

function formatF(n:Number,dec:uint):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];
}
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 23, 2010 Dec 23, 2010

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];

}
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
Guest
Dec 23, 2010 Dec 23, 2010

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

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 24, 2010 Dec 24, 2010

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

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
Guest
Dec 24, 2010 Dec 24, 2010

show code please.

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 24, 2010 Dec 24, 2010

Well, is it necessary?

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 24, 2010 Dec 24, 2010

hh is trying to be helpful but doesn't understand the issue.  use the code i suggested.

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 24, 2010 Dec 24, 2010

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?

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 24, 2010 Dec 24, 2010
LATEST

copy and paste the code you're using that's related to those two 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