How do I format numbers?

0 favourites
  • 3 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
  • How do I format numbers?

    For example I want to do something like "%5.2f".

    5.1, 12.05 and 3.006 should be " 5.10", "12.05" and " 3.01". keep in mind the spaces.

    I know how to work around that, but it doesn't seem elegant enough.

    My problem might seem similar to:

    but it's not the same ^^ I don't want "at most" 2 decimal points. I want it to be constant. round(number*100)/100 won't work, because 1 would be still 1, not 1.00, also it doesn't help me with spaces.

  • The zeropad() expression is helpful here. Example:

    var=5.1

    text = int(var) &"."&zeropad(round((var%1)*100), 2)

    Could have issues with a number like 1.995 though. Another option is some plugin ( the forum has a listing in the plugin section that can be looked through) or using some javascript through the browser object's browser.execjs() expression. Example:

    set text to browser.execjs("parseFloat(Math.round("& var &" * 100) / 100).toFixed(2);")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct 2 doesn't have any formatting helper... you need to create your own formatting expression.

    I guess this could work :

    right(" " & floor(number), 2) & "." & zeropad(round(number * 100) % 100, 2)[/code:zk73q0i1]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)