How do I show a number with thousand separator?

Just started using Construct 2? Post your questions here

Post » Fri Sep 19, 2014 6:37 pm

This is a basic thing to add in normal programming, but I can't for the life of me find out how to do it in Construct 2...

Fx. the number 1,000,000,000 looks quite unreadable when displayed as 1000000000...

I'm making a game for which this will eventually be an issue (the user must be able to quickly read and compare very large numbers; billions to trillions to quadrillions etc.).


Edit:

My current workaround which I'll have to use if I can't display the thousands separator, would be IF-statements;

fx. this (it was faster to just type like this than explain how to drag/drop in Construct 2)...:
if (variable > 999999) { variable = (variable/1000000) & "million" }


Btw. I also thought about counthing the string length for each number, then breaking it apart in to a certain number of variables, then reassembling into one number with my , separator in between... but I certainly hope that there's a more nice solution ^_^
B
12
S
2
Posts: 80
Reputation: 816

Post » Fri Sep 19, 2014 10:26 pm

Go to github. Search for sprintf for JavaScript. Call it with the browser object passing in your string and display the result.
[b]Andrew Donelson[b]
Nlaak Studios, LLC
https://www.nlaak.com/
[email protected]
B
15
S
3
Posts: 66
Reputation: 1,136


Post » Sat Sep 20, 2014 3:36 pm

Thanks a lot, R0J0hound, may I ask how you found these threads...? I tried searching here and directly on Google, and came up empty handed... Also tried the manual of course, but no dice... ^_^

I'd hoped for a thing similar to how "round" works, just with a parameter setting - but this is also a very viable workaround/solution you've linked to here! So thanks a bunch! :D
B
12
S
2
Posts: 80
Reputation: 816

Post » Sat Sep 20, 2014 3:39 pm

OOOOH and I just saw the other links - when I read the manual, I did wonder if regex could do the trick - and voila! And now I also learned about functions in Construct!

I'm getting exponentially happier and happier for Construct as I learn it - DAMN it's PERFECT for me! It's like sculpting with very easy to use tools aka "make dinosaur button", and then being able to dive in with more precise tools, to make exactly what you want and need!

Uuuuh time to play with regular expressions now! :D Thanks again!
B
12
S
2
Posts: 80
Reputation: 816

Post » Sat Sep 20, 2014 5:10 pm

Glad they helped. I found the topics using the forum search with "comma number".
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Sat Sep 20, 2014 10:56 pm

Ah! I searched for "thousand separator" and "million separator" ^_^
B
12
S
2
Posts: 80
Reputation: 816


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest