A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: decimal cases

  1. #1
    Junior Member
    Join Date
    May 2001
    Posts
    19
    Hi,

    I need a problem with dynamic text filds to display decimal cases.

    My function is:

    function decimal (result) {
    final = int(result*100)/100;
    var dec = (final-(parseInt(final)));
    if (dec == 0) {
    final = (String(parseInt(final))+".00");
    }
    if ((length(dec))<4) {
    final = (String(parseInt(final))+"."+(dec*10)+"0");
    }
    return (final);
    }

    I have looped objects that re-display the values to text filds, but always when the second case after the "." is zero , the second case is not displayed in the result.

    Should someone help me?

    thanks

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Not too pretty function, but it works:

    Code:
    function decimal (mynumber) {
        var dec = mynumber.slice(0, mynumber.indexOf(".", 0)+2+1);
        if (mynumber.indexOf(".", 0) == mynumber.length-2 and mynumber.indexOf(".", 0)<>-1) {
            dec = dec+"0";
        }
        if (mynumber.indexOf(".", 0) == -1) {
            dec = dec+".00";
        }
        if (mynumber.indexOf(".", 0) == mynumber.length-1) {
            dec = dec+"00";
        }
        if (mynumber.length==0) {
            dec = "0.00";
        }
        return (dec);
    }
    Hope you can use this

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