A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] Scientific notation?

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Location
    Ags.,Mx
    Posts
    14

    resolved [RESOLVED] Scientific notation?

    Hi, I have a problem, I am designing a Coulomb Law's simulation in KoolMoves but I work with small and big numbers for example 0.0000001656 or 1212121212.1235, I need to convert that in scientific notation (1.656e-7 or 1.212e+10), Can you help me? please...

    this is importat for me, help me please... thanks...

  2. #2
    undead creature necromanthus's Avatar
    Join Date
    Feb 2002
    Location
    ROM
    Posts
    1,890
    Create a single keyframe movie, insert a dynamic text field (txt1) in that frame and set this script in the main timeline:

    n = "0.0000001656";
    txt1.text = Number(n);
    stop();

    Tell us the result.

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Location
    Ags.,Mx
    Posts
    14
    Thanks necromanthus, but if I have a 3 dynamic text, a button and a single keyframe movie, and in this button I do math operations with the 3 dynamic text (for example txt1*txt2*txt3=txt4)and I want to send the results to another dynamic text(for exaple txt4) but send it with the scientific notation and use only 3 decimals, for example "1.234e+5".... this is possible? Thanks!
    Last edited by manuel-jrs; 07-20-2008 at 10:43 PM.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I believe his point is that you should force flash to convert the text to numbers first.

    Code:
    txt4.text=Number(txt1.text)+Number(txt2.text)+Number(txt3.text)
    should do what you want.

  5. #5
    Junior Member
    Join Date
    Jul 2008
    Location
    Ags.,Mx
    Posts
    14

    resolved Hi

    Hi, I use this and I got a good results... Thanks...

    function formatDecimals(num, digits) {
    if (digits <= 0) {
    return Math.round(num);
    }
    var tenToPower = Math.pow(10, digits);
    var cropped = String(Math.round(num * tenToPower) / tenToPower);

    if (cropped.indexOf(".") == -1) {
    cropped += ".0";
    }

    var halves = cropped.split(".");

    var zerosNeeded = digits - halves[1].length;
    for (var i=1; i <= zerosNeeded; i++) {
    cropped += "0";
    }
    return(cropped);
    }

    function toScientific(num, sigDigs) {

    num = Number(num);
    if (isNaN(num)) return num;

    var exponent = Math.floor(Math.log(Math.abs(num)) / Math.LN10);
    if (num == 0) exponent = 0;

    var tenToPower = Math.pow(10, exponent);
    var mantissa = num / tenToPower;

    mantissa = formatDecimals(mantissa, sigDigs-1);
    var output = mantissa;

    if (exponent != 0) {
    output += "e" + exponent;
    }
    return(output);

    }

  6. #6
    Junior Member
    Join Date
    Jul 2008
    Location
    Ags.,Mx
    Posts
    14

    resolved

    [resolved]

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    That's great but I really don't think you needed to do all that. When I tried it with just forcing the conversion to number it should in in scientific notation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center