Topic
  • 4 replies
  • Latest Post - ‏2013-06-11T17:44:28Z by trang@oxford
trang@oxford
trang@oxford
4 Posts

Pinned topic How to SUM decimal fields

‏2013-06-10T18:22:29Z |

I extract multiple amount fields with decimal. For example amount1(200.12), amount2(125.06), amount3(266.00). How do I total all the fields with decimal? Please help.    

  • tmparker
    tmparker
    534 Posts

    Re: How to SUM decimal fields

    ‏2013-06-10T20:51:56Z  

    I guess it really depends on where you want to sum up these values.  Are you trying to do this directly in a macro, or in business logic, or somewhere else?  This should be pretty simple to do in business logic.  All you need to do is convert the string to a numeric value.  If this is for currency values you probably want to use something like BigDecimal.

    Thanks

    Tim

  • trang@oxford
    trang@oxford
    4 Posts

    Re: How to SUM decimal fields

    ‏2013-06-10T23:02:08Z  
    • tmparker
    • ‏2013-06-10T20:51:56Z

    I guess it really depends on where you want to sum up these values.  Are you trying to do this directly in a macro, or in business logic, or somewhere else?  This should be pretty simple to do in business logic.  All you need to do is convert the string to a numeric value.  If this is for currency values you probably want to use something like BigDecimal.

    Thanks

    Tim

    How could I do this calculation directly in a macro? Could you give me an example? Thanks for the quick advise. Trang

  • tmparker
    tmparker
    534 Posts

    Re: How to SUM decimal fields

    ‏2013-06-11T07:01:24Z  

    How could I do this calculation directly in a macro? Could you give me an example? Thanks for the quick advise. Trang

    Here is a simple example to try and show you how this can be done directly in a macro.  You have to use the advanced macro format so that you can use macro variables to store the values and do the calculations.  In the example I simply extracted 2 values from the host screen and stored them in macro variables that I created with a type of  double.  Then I simply added them up and stuck the total in an input field on the host just to show that it could be done.  You would need to write the code to meet your needs.

    This macro was written to run using the iseriesd.demos.ibm.com server.

    I am attaching the macro file itself so you can see the code.

    Thanks

    Tim

    Attachments

  • trang@oxford
    trang@oxford
    4 Posts

    Re: How to SUM decimal fields

    ‏2013-06-11T17:44:28Z  
    • tmparker
    • ‏2013-06-11T07:01:24Z

    Here is a simple example to try and show you how this can be done directly in a macro.  You have to use the advanced macro format so that you can use macro variables to store the values and do the calculations.  In the example I simply extracted 2 values from the host screen and stored them in macro variables that I created with a type of  double.  Then I simply added them up and stuck the total in an input field on the host just to show that it could be done.  You would need to write the code to meet your needs.

    This macro was written to run using the iseriesd.demos.ibm.com server.

    I am attaching the macro file itself so you can see the code.

    Thanks

    Tim

    Hi Tim,

    Thank you very much for your help. It works like a charm. :)

    Thanks,

    Trang