Best way to have a printed variable display a "+" sign when it's positive and "-" sign when it's negative

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.9
Story Format: Sugarcube 2.31.1

Hello, so imagine I have a variable which is for example, $fundschange, depicting a change in your funds ($funds variable). This could either be an increase or a decrease depending on the event, and when this happens, I would like to tell the player with something like:

“Funds: £$funds ($fundschange)”

The twist is I would like to add a + sign before $fundschange when it is positive and a - sign when $fundschange is negative, so for example it looks like:

“Funds: £550 (+50)”

or

“Funds: £450 (-50)”

Is there another way of doing this than putting an <<if $fundschange gt 0>> clause every time?

Thanks.

You could use a conditional operator if you want to shorten it a bit. So you’d do something like this:

Funds: £$funds (<<= $fundschange > 0 ? "+" : "">>$fundschange)

So if $fundschange is greater than zero, then a “+” will be displayed in front of the value, otherwise nothing will be added to the front. Change “>” to “>=” if you want a “+” in front of zeros as well. (<<=>> is a shorthand version of the <<print>> macro.)

Enjoy! :grinning: