Jump to content
thy_

[SOLVED] Dealing with 20 minus 60 should be positive 40

Recommended Posts

Is there a way to skip a conditional to avoid negative numbers?

 

_balance expected:

_A = 20;
_B = 10;

_balance = _A - _B; // results 10

_balance reality: 😅

_A = 20;
_B = 60;

_balance = _A - _B; // results -40

A lazy solution:

_A = 20;
_B = 60;
_balance = 0;

if ( _A > _B ) then { _balance = _A - _B } else { _balance = _B - _A };  // results 40 always

 

Show me what you got...

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×