Adding text into a currency variable


#1

Hello there.

I’m working on setting variables to subtract a couple of fields and get a result. No problem there. I added a $ and decimal feature to the script to get $10.00. When I get a negative number it formats it as $-10.00. How can I get the $ sign to be inside the negative number?

money formatting.rp (61.9 KB)


#2

Hey there,

One way to do this is to add a global variable (set to the same value as diffTotal) and some conditional logic to check to see if that variable is greater than or = 0.

You can use the logic you’ve already got, just change it to:

 -$[[((LVAR1 - LVAR2)*-1).toFixed(2)]].

This way you place the ‘-’ outside of the dollar sign, and you multiply the sum by -1.

Make sure you toggle ‘if/else’ on your cases, so that each case reads IF. Here’s the file with those updates:

money formatting.rp (65.9 KB)

Note** In my file I used a widget to test my variable. I deleted the widget, but forgot to delete the logic to update the text on the widget.


#3

If you wanted to avoid two cases, you could make the whole thing a string and then replace the ‘$-’ with ‘-$’ like this:

[[((’$’).concat((LVAR1 - LVAR2).toFixed(2))).replace(’$-’,’-$’)]].

money formatting.rp (62.3 KB)

To break this down:
We start with a string of ‘$’, then append your formatted number, and finally
search the resulting string for ‘$-’ and if if’ts found replace that with ‘-$’.


#4

Thanks for both of the solutions. They worked perfectly.


#5

Ok. One more thing.

What if i want to have a couple of fields (supp1 and supp2) total down to suppTotal and that does the combination with diffTotal to put the results in diffReadOnly (see enclosed project)?

I can make the diffTotal add up supp1 and supp2, but i keep failing at then getting that to put that result in diffReadOnly. I’ll keep at it in the meantime.

Thanks for your help.

money formatting_2.rp (60.7 KB)


#6

So suppTotal is the sum of supp1 and supp2. diffReadOnly is borrowTotal - suppTotal?


#7

I had to look at it twice to be sure, but yes.


#8

Have a look at the attached. I centralized the logic to “onMove” of your diff total so you don’t have to update so many different places with logic. Then each text field has a case that says to move the diff field on text change. Let me know if you have any questions.

money formatting2.rp (64.7 KB)


#9

Thanks. I’ll dig into it. I’m sure I’ll have more questions as i’m totally new to the variables thing.

Much appreciated.


closed #10