ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Comparing variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comparing variables

    Dear All,
    i have two variables both type 18P 0
    Amount And Total Balance

    Amount is 24000000(2hundred and fourty)
    and TotalBalance is : 1015147077
    With last two digits as decimals
    am trying an if condition based on below but it
    is not entering rhe condition even though the condition is true

    Amount>totalbalance*(10/100)
    anything wrong with my variable types?

    thank u in advance
    regards

  • #2
    Try

    Code:
    if Amount > (totalbalance * 10) / 100

    Comment


    • #3
      Goodness knows why these variables are not defined properly (i.e. with the correct decimal places) but your data indicates that Amount has 240.00000 and TotalBalance 10,151,470.77 so the definitions should be 18p 5 and 18p 2 respectively.

      Given the values you quote then TotalBalance is significantly larger than Amount so it shouldn't trigger the condition. But is it a straight comparison you are trying to do - or are you trying to say something like "Is Amount > 1% of TotalBalance" ?

      If you just need to directly compare the two values you either need to multiply TotalBalance by 1,000 or divide AmountDue by 1,000. So:
      Code:
      If Amount > (TotalBalance * 1000);
      // Or
      If (Amount / 1000) > TotalBalance;
      But why not make life easy and define the variables correctly?

      Comment


      • #4
        Thank u
        the thing is that they are variable fixed this way in the database and i need to compare the amount with 10% of the total balance

        Comment


        • #5
          I'm not sure "database" is the right term if there is this kind of data <grin>

          OK - so if you are comparing to 10% just reduce the 1,000 to 100 and you're there.

          Comment

          Working...
          X