How do I Format Numbers as Currency?

0 favourites
  • 5 posts
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • Hi guys!

    I'm new to Construct 2 and the forums. I discovered this great piece of software a few weeks ago, and I can't believe how awesome it is! I'll definitely upgrade to the full version by the end of this month !

    Anyway, I'm trying to build a money system, and I'm stuck at the following:

    What I've done so far:

    * I've created a text object named "txt_cash",

    * a global variable named "cash".

    I'm using the "rex_systemext"-plugin, to create the decimal seperators, and this works great (for example: "1123.45" is showing as "1.123,45".), however, when the value in my global variable "cash" is, let's say, "34.50", it's showing "34,5" instead of "34,50". Same goes for round numbers... instead of showing "50,00", it's showing "50".

    Right now I have: Every tick -> set text "txt_cash" to -> SysExt.ToDecimalMark(cash)

    Does anyone know what I should add to the above line to fix this problem?

    Any help would be greatly, greatly appreciated!

  • variable Cents=0

    Set Cents to round((cash-int(cash))*100)

    Set text "txt_cash" to -> int(cash) & "." & zeropad(Cents,2)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • variable Cents=0

    Set Cents to round((cash-int(cash))*100)

    Set text "txt_cash" to -> int(cash) & "." & zeropad(Cents,2)

    Thank you so much, dop2000! Your method works great if the amount of cash stays under one thousand (999.99), but what if the amount of cash is higher, like "1,500.35" or "1,500,000.35"? With your method it's showing as "1500.35" or "1500000.35"

    Thanks again for your help so far!

  • You can use your method for separating digits:

    SysExt.ToDecimalMark(int(cash)) & "." & zeropad(Cents,2)

  • You can use your method for separating digits:

    SysExt.ToDecimalMark(int(cash)) & "." & zeropad(Cents,2)

    You're the best, works like a charm!

    Thanks for your help and your prompt reply

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