How do I always display two decimals?

Get help using Construct 2

Post » Sat Sep 12, 2015 9:36 pm

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!
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Sep 12, 2015 9:42 pm

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)
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Sat Sep 12, 2015 9:47 pm

https://www.scirra.com/tutorials/search?q=decimals

check the link above :D


Edited ... now i look like an asshole ... lol ... sorry i could not help you to much...
Last edited by gamecorpstudio on Sun Sep 13, 2015 8:59 am, edited 1 time in total.
B
75
S
22
G
68
Posts: 1,337
Reputation: 43,271

Post » Sat Sep 12, 2015 10:16 pm

Thank you very much Paulscottrobson, that sounds like simple way of handling it!
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Sep 12, 2015 10:46 pm

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.
B
9
S
1
Posts: 97
Reputation: 715

Post » Sun Sep 13, 2015 5:34 am

round(number*100)/100 ?
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832


Return to How do I....?

Who is online

Users browsing this forum: AndreasR and 13 guests