Formatting Negative Numbers

Hello,

How do I format a negative number to appear in parenthesis?

Example: - 30.000,00 € to (30.000,00) €

I already have a script to convert to euro currency

var field, result = “”;

field = record.fields[“gesamtsumme_brutto”];
if (field !== “”) result += formatter.currencyNoSymbol(field) + " \u20AC";

results.html(result);

Thanks

Hi cnavarro,

I could not get the currency right in the data mapper, so I went with what is below.

var field, result = “”;
field = record.fields[“gesamtsumme_brutto”].replace(“-”, “”).replace(“\u20AC”,“”).trim();
if (field !== “”) result += “(” + field + “)” + " \u20AC";

results.html(result)

EDIT: Sorry I overlooked the Euro symbol. Updated code.

Hope that helps.

Regards,

S

In the Designer you can use the formatter object in your User scripts (e.g. the scripts residing in the Scripts pane). The formatter object lets you format values of common field types like numbers, currencies and dates.

Several functions allow you to specify a pattern. The following pattern will wrap negative values with parenthesis.

var field, result = "";
field = record.fields.somefield;
result = formatter.number( field, '#,##0.00 €;(#.##0,00) €');
results.html( result );

See the online help for more information on these patterns.

Hope this is of some help,

Erik

Thank you, it works great but the variable is on a detail table, therefore there are multiple line items and they could be positive and negative values, applying this script all numbers show up in parenthesis

What do you want the numbers that are not negative to look like?

Must they remain 30.000,00 €?

Regards,

S

yes please

positive numbers 30.000,00 €

negative numbers (25.000,21) €

Thank you

Here you go.

https://learn.objectiflune.com/qa-blobs/4140154119489647955.zip

Regards,

S