How do I show a percentage without showing a bunch of decimal places...?

0 favourites
  • 5 posts
From the Asset Store
Spooky Places game assets for 2D endless runner action adventure game.
  • Hi there,

    creating an little practice quiz activity which counts the number of tries to show a final percentage score.

    (correct/tries) *100 & "%"

    However if you get 2 out of 3 the result is 66.6666666666667%

    How do I truncate this so it only shows 66%?

    I have tried "Round" but that does not seem to work...?

    Any advice would be greatly appreciated.

    Thanks!

  • round(x) Round x to the nearest whole number e.g. round(5.6) = 6

    floor(x) Round down x e.g. floor(5.9) = 5

    You can try using left("66.6666",".")

  • Thanks for the response, I cannot get the syntax correct in my code?

    Original code (RKScore/tries) *100 & "%"

    New code round(RKScore/tries) *100 & "%"

    The result keeps rounding up to 100% from 66%.

    What does the X in round(x) represent?

    Thanks for more guidance :-)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • int(yourpercentage*100)/100 should give you 2 decimal points

  • Thanks for the response, I cannot get the syntax correct in my code?

    Original code (RKScore/tries) *100 & "%"

    New code round(RKScore/tries) *100 & "%"

    The result keeps rounding up to 100% from 66%.

    What does the X in round(x) represent?

    Thanks for more guidance :-)

    X represents what you want to round, try this:

    round ((RKScore/tries)*100) & "%"

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)