Convert to Currency

My Payment Amount Field pass the data in 80624. I want to convert this into currency format of $806.24.

Below is what I have created but I get and error “missing before state Payment Amount post functions”

var ACINT = data.extract(‘Payment Amount’,0,1,“<br />”);

ACINT = ACINT.substr(0,ACINT.length-2) + ‘.’ + ACINT.substr(ACINT.length-2);

Any advise would be appreciated.

A currency is just a value that can have up to 2 decimals. You don’t “format” the currency in the DataMapper, you only extract the value. Then, in the Designer, you decide how to display it.

So in the DataMapper, all you need to do is set the code for your Field Extraction to look like this:

data.extract('Payment Amount',0,1,"")/100;

Make sure you set the Field Type to Currency, then clear all the settings in the Data Format section for that field (because those settings are only used to help the DataMapper read the value from the input file, not to format the output).

Then, in the Designer, drag and drop that field on your template. A default currency format will be used, but you can change it by simply double-clicking on the appropriate script.

Hi Phil,

I put this in my Post function and clear out Data format. Still have the same error as before.

var ACINT = data.extract(‘Payment Amount’,0,1,“”)/100;
ACINT = ACINT.substr(0,ACINT.length-2) + ‘.’ + ACINT.substr(ACINT.length-2);

I get it work. Thank you.

If you are looking to do this in the connect designer.

var str=“80624”;

var resStr=str.substring(0,str.length-2)+“.”+str.substring(str.length-2);

results.text(formatter.currency(resStr));