dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Display percentage?

  1. #1
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    Display percentage?

    I bet the answer lies within the preloaders and I could study them to reach it, but to cut a corner.

    If I want to display the percentage, by calculating it, e.g.:
    65 / 250 gives the result 0.264 and means that 65 is 26.4 percent of 250

    But how do I make my flashmovie display only 26 ? Or even in som cases there would be more decimals and I could be satisfied with the display of 2 like this 0.26 - buit not more, how is that possible?
    http://www.sdax.se Chess, Trotting and Blog

  2. #2
    Member
    Join Date
    Jul 2007
    Posts
    91
    Math.round(number) ??

  3. #3
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    That would turn 26.4 into 26 surely, but how to turn 0.264 into 26?

    EDIT* wait a minute ( times 100 and Math.round(number) )would do it! Solved!
    Last edited by SirN; 03-10-2010 at 10:31 PM.
    http://www.sdax.se Chess, Trotting and Blog

  4. #4
    Member
    Join Date
    Jul 2007
    Posts
    91
    Code:
    //n = number;
    //m = numbers after the decimal point;
    Math.roundN = function (n,m) {
        return Math.round((n*Math.pow(10,m)))/Math.pow(10,m)
    } 
    //example
    my_num = Math.roundN((1.12345), 2);
    Last edited by 3DH; 03-11-2010 at 12:49 AM.

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