How do I format the result as money value?

Just started using Construct 2? Post your questions here

Post » Wed Dec 21, 2016 5:16 pm

I believe this is easy but not for me. I'm adding up some values and I want the total to look like this: $ 1,000 instead $ 1.000
B
4
S
2
Posts: 123
Reputation: 846

Post » Wed Dec 21, 2016 6:48 pm

HA! You would think so, but it's actually been asked quite a lot of times around here.

1st, set the function.

'Function' > On (name your function) - 'Function' > Set return value to RegexReplace(Function.Param(0) & "", "(\d)(?=(\d{3})+$)", "g", "$&,")


Then -

YourTextBox > Set text to Function.Call("name your function", GlobalVariable)

From the 1st part (name your function) will be the same as the 2nd part ("name your function"

This will only give you the commas: i.e $1,000,000
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Thu Dec 22, 2016 10:26 am

Hey jeffige

Thank you so much for this solution.

I am having two issues now :

- During the sum, I need to add a percent of the value and I need to keep this format: 1.32. For this, I am using round((variable*0.02)/100)*100 but sometime I get only 0. Other example: if I have 2985 and I use round((variable*0.05)/100)*100 I am getting 100 instead of 149.25

- At the end I am using your instructions and I am not getting the cents (1,001.32). I believe it happens because the another issue.
B
4
S
2
Posts: 123
Reputation: 846

Post » Fri Dec 23, 2016 9:12 am

Hey guys

I still need a little help here.

I have figured out part of the problem: I inverted the operators. So the right is: round((variable*percent)*100)/100

But if the value have cents, instead of 1,001.32, I am getting 1001.32. I need to rounded the value (remove the cents) to get 1,001 but I really need to get 1,001.32
B
4
S
2
Posts: 123
Reputation: 846

Post » Fri Dec 23, 2016 2:27 pm

It was a little challenge =]

Image
Image
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,028

Post » Sat Dec 24, 2016 12:31 pm

TELLES0808 wrote:It was a little challenge =]

Image
Image


Sorry the delay and thanks for the help.

As I have more than 5 text objects it's better if I use a function for this, right? I will give it a try.
B
4
S
2
Posts: 123
Reputation: 846

Post » Sat Dec 24, 2016 11:38 pm

You don't need functions, you can simple filter usina the same condition of the trigger for the function
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,028


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests