PDA

View Full Version : Adding commas and dollar signs


KatJones
February 14th, 2013, 09:07 AM
I am sure this has been asked and discussed in maybe a different way. But I have search the forums and can't find a simple solution.

I have 5 data fields with dollar amounts in them. None have commas, or dollar signs.

In a perfect world I would just use the Number to Currency wizard for all 5 fields that FusionPro gives however....

Not all the data in those fields are numbers, some is text and they change whereas sometimes the "Other $_______ may be in field named AMT1 position.

Example:
Amt1= 25
Amt2= 50
Amt3=75
Amt4=100
Amt5=Other $________

Example2:
Amt1= Other $________
Amt2=(Blank--will be suppressed)
Amt3=(Blank--will be suppressed)
Amt4=(Blank--will be suppressed)
Amt5=(Blank--will be suppressed)

Example3:
Amt1= 25
Amt2= 50
Amt3=Other $________
Amt4=(Blank--will be suppressed)
Amt5=(Blank--will be suppressed)

I need to make it where the rule searches the field for numbers only and convert to currency formatting. And if it has text do not format.

step
February 14th, 2013, 11:02 AM
Assuming you're trying to list these in one text field, this might work for you:


var amt = [];

for (var i=1; i<=5; i++){
(Field("Amt" + i) != "") ? amt.push(Field("Amt" + i)) : "";
}

return amt.join("<br>").replace(/(\d+)/g,function(n){return FormatNumber("$###,###,###.00",n);});