I ended up using a simple, brute force method to (where applicable) turn any value up to $999999 into something more appropriate for display, e.g. $23,795, using the ability to extract / overwrite particular letters or numbers in variable values. In short, it treats the value as a string, not numeric, since it’s purely for display purposes.
I’ll lay out the whole thing here in step-by-step fashion but it should be easy enough to tweak to suit particular needs, and thereby reduce the number of lines used / needed.
*set word "${wealth}"
*comment turn value into a 6-digit number by prefixing with zeros
*if length(word) = 1
*set word (("0"&"0")&("0"&"0"))&("0"&(word#1))
*if length(word) = 2
*set word (("0"&"0")&("0"&"0"))&((word#1)&(word#2))
*if length(word) = 3
*set word (("0"&"0")&("0"&(word#1)))&((word#2)&(word#3))
*if length(word) = 4
*set word (("0"&"0")&((word#1)&(word#2)))&((word#3)&(word#4))
*if length(word) = 5
*set word (("0"&(word#1))&((word#2)&(word#3)))&((word#4)&(word#5))
*comment insert comma in middle of 6-digit currency value
*if length(word) = 6
*set word (((word#1)&(word#2))&((word#3)&(",")))&(((word#4)&(word#5))&(word#6))
*comment remove leading zeros one at a time, including comma if not needed
*if (word#1) = "0"
*set word (((word#2)&(word#3))&((word#4)&(word#5)))&((word#6)&(word#7))
*if (word#1) = "0"
*set word (((word#2)&(word#3))&((word#4)&(word#5)))&(word#6)
*if (word#1) = "0"
*set word ((word#3)&(word#4))&(word#5)
*if (word#1) = "0"
*set word (word#2)&(word#3)
*if (word#1) = "0"
*set word (word#2)
Note that while the following, more obvious method works in practice, it actually generates a ‘fake bug’ in QuickTest on the *set lines (in the event the value of word
is fewer than x-characters in length, despite the specific *if condition).
*set word "${wealth}"
*if length(word) < 4
*goto next
*if length(word) = 4
*set word (((word#1)&(","))&((word#2)&(word#3)))&(word#4)
*goto next
*if length(word) = 5
*set word (((word#1)&(word#2))&((",")&(word#3)))&((word#4)&(word#5))
*goto next
*if length(word) = 6
*set word (((word#1)&(word#2))&((word#3)&(",")))&(((word#4)&(word#5))&(word#6))
*goto next
*label next