CalcBuilder Forum

Conditional Output - put negative numbers in brackets

User Krx 2019-01-15 18:02:42

Hello

I'm doing a calculator for US visitors.
In their accounting instead of writing negative number as caclulated output they are putting it in brackets
so if i have this setup:
$field1 - number field
$field2 - number field
$field3 - inline result
and set this code: $field3 = $field1 - $field2 which results with for example 2 - 4 = -2
how to set up things so that instead of -2 it displays: (2) - number 2 in brackets

So I need a way to display all negative numbers in brackets, without minus in a front.
Positive numbers should be displayed without brackets.

Is this possible?
I tried to put my own if else code but it didn't work.
Maybe I need to use different syntax?

I found similar thread but didn't want to necro it:
https://www.moonsoft.es/forums/2-cbsupport/840-conditional-output

Regards

Moonsoft support 2019-01-15 18:15:00

Hello,
if you have calcbuilder extended you could add this format directly at the excel sheet, if you feel more comfortable there than handling php code. Otherwise, you can format the code at the end of the php section (and setting the excel configuration to launch before the php code), something like this would do the work:

if($field3<0){
$field3=$field3*-1; //get rid of minus sign
$field3="(".$field3.")"; //enclose in brakets
}

Hope this helps, regards

...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!
...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!