# Calculation Help

• 08-16-2019, 01:07 PM
johnkoh
Calculation Help
Hi All,

Simple calculation and have trouble when it is negative number

I have this and
1. Is there better way to calculate the Balance?
2. Do I have to change negative to positive number?

Code:

```'add number a = 542 b = -211                'negative number c = 186 d = 374 x = a+b+c+d                'Get total -- ok 'get the balance 'balance = a - b                'It is wrong result when the number is negative. Unknown negative number or not if b < 0 then         'msgbox("b is less than 0 and ...")         'How to change to positive number?         balance = a + b                'Unknown negative number or not else         balance = a - b                'Unknown negative number or not end if ui_msg_box("result","balance "+balance)```
• 08-16-2019, 07:33 PM
Al Buchholz
Re: Calculation Help
if a,b,c,d are transactions, what is the beginning balance?

Zero?

What do you expect the balance to be?
• 08-16-2019, 07:54 PM
johnkoh
Re: Calculation Help
Hi Al,

It is general subtract calculation, not typical "Balance" calculation.

what is the beginning balance? -- "A" Value
What do you expect the balance to be? --> a(*542) - b(*211) = 331.00

I want to write a code as xBal = a - b but when the "B" is negative number then trouble.

Thank you
• 08-16-2019, 08:27 PM
Al Buchholz
Re: Calculation Help
Quote:

Originally Posted by johnkoh
Hi Al,

It is general subtract calculation, not typical "Balance" calculation.

what is the beginning balance? -- "A" Value
What do you expect the balance to be? --> a(*542) - b(*211) = 331.00

I want to write a code as xBal = a - b but when the "B" is negative number then trouble.

Thank you

a-abs(b)
• 08-19-2019, 08:14 AM
johnkoh
Re: Calculation Help
Thanks, Al