How do I always display two decimals?

Not favoritedFavorited Favorited 0 favourites
  • 6 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • Hi!

    I'm trying to have a currency system with two decimals in my game. How can I make the heads up display always show the two decimals, even when the value happens to be a round number? In other words my problem is that round values like two are displaying as 2 $ instead of 2.00 $. I tried to search but couldn't really find anything on this subject. Any help would be appreciated!

  • Multiply it by 100, this will convert 33.1 to 3310 ; then the pre decimals part is everything up to the last two digits (33) and the post decimals the last two (10)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • https://www.scirra.com/tutorials/search?q=decimals

    check the link above <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Edited ... now i look like an ******* ... lol ... sorry i could not help you to much...

  • Thank you very much Paulscottrobson, that sounds like simple way of handling it!

  • Just in case this helps someone else searching for this information, here's the expression I ended up using for my HUD:

    set text to "= " & left(str(money*100), len(str(money*100))-2) & "." & right(str(money*100), 2)

    There is one small weakness with this method: if the number is zero then there will be no decimals. But that one exception can be easily taken care of with an if-statement.

    EDIT: Actually there is the problem that if the original value is less than one (for example a decimal like 0.50) then we only get a number with two digits and the above expression stops working. I need to research this a bit more.

  • round(number*100)/100 ?

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