Copy link to clipboard
Copied
In my job function I have to combine fields to generate letters for different departments. I can usually cobble together a working form, but in this case I'm hitting a wall. I'm trying to combine a text field with a number field without loosing my number field formatting.
Example: The following results in "The cost is 1000" while I am trying to get "The cost is $1,000.00"
var cost = "The cost is ";
var OS = this.getField("Old Salary").value
event.value = cost + OS;
If this is just to display an output (not to be calculated any further with other fields), then You can use custom calculation script with arbitraty mask using the "util.printx()" method
Use it like this :
var v = this.getField("Old Salary").value;
v = util.printx("$9,9999", v);
event.value = "The cost is " +v;
Just move comma from this $9,9999 to this $99,999 but be warned then it won't show 1,000 it will show 10,00
EDIT: If you want to show both 1,000 and 10,000 replace this line: v = util.printx("$9,9999", v);
with this: v = util.printf("$%,0.0f", v);
If you also want to add decimal,replace second zero with number of desired decimals.
Copy link to clipboard
Copied
If this is just to display an output (not to be calculated any further with other fields), then You can use custom calculation script with arbitraty mask using the "util.printx()" method
Use it like this :
var v = this.getField("Old Salary").value;
v = util.printx("$9,9999", v);
event.value = "The cost is " +v;
Copy link to clipboard
Copied
This is great! Is there a way to format it if the number of digits isn't fixed? In the above example the "$10,000" comes out as "$1,0000".
Copy link to clipboard
Copied
Just move comma from this $9,9999 to this $99,999 but be warned then it won't show 1,000 it will show 10,00
EDIT: If you want to show both 1,000 and 10,000 replace this line: v = util.printx("$9,9999", v);
with this: v = util.printf("$%,0.0f", v);
If you also want to add decimal,replace second zero with number of desired decimals.
Copy link to clipboard
Copied
This worked exactly as I wanted. Thanks!
var v = this.getField("Old Salary").value;
v = util.printf("$%,0.2f", v);
event.value = "The cost is " + v;
Copy link to clipboard
Copied
Hey Jason!
Glad that this helped. Don't forget to mark NesaNurani's answer as correct solution, thank you.