Help with data-type casting.

vanolind
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 07/17/2009
Points: 30

Hello, Im trying to make a macro that takes in a document, formatted like this example:

<financeData>
                      <investment>10000.0</investment>
                      <compoundPY>4.0</compoundPY>
                      <yearsCompounded>1.0</yearsCompounded>
                      <rate>0.01</rate>

</financeData>

It is to be used to calculate compound interest.  I currently have a trival mash, that all its doing is when invoked, gives this same Data.

 

When i recieve the data in my macro testing EMML file, I can successfully get the data into variables using this snippet of code:

<invoke service="testStuff" operation="Invoke" outputvariable="result" />

    <assign fromexpr="$result/*:financeData/*:investment/string()"
        outputvariable="intitialInvestment" />
    <assign fromexpr="$result/*:financeData/*:compoundPY/string()"
        outputvariable="compoundPerYear" />
    <assign fromexpr="$result/*:financeData/*:yCompounded/string()"
        outputvariable="yearsCompounded" />
    <assign fromexpr="$result/*:financeData/*:rate/string()" outputvariable="iRate" />

 

However I need to process the data using arithmatic operations, preferably using them as decimal variables.  I know there must be a simple way of converting the data to a decimal, I just can't figure out how.  If some one could let me know that would be great!  thanks for putting up with me!

-Mike

The Noobie Masher

0
Your rating: None
Mythri
User offline. Last seen 1 year 7 weeks ago. Offline
Joined: 12/18/2008
Points: 0

Hi Mike,

Please try using the number() function instead of string()

Similar to:

<assign fromexpr="$result/*:financeData/*:investment/number()"
        outputvariable="intitialInvestment" />

This should give you a numeric value of the data inside the specific tag (<investment> in this case)

-Mythri

vanolind
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 07/17/2009
Points: 30

Does number() support decimal operations?  Or does it make it an integer? And would the format "1.0" make it misread it?  Because it seems to skip right past the values in the document now.

Mythri
User offline. Last seen 1 year 7 weeks ago. Offline
Joined: 12/18/2008
Points: 0

Hi Mike,

number() supports decimal operations as well. You can perform arithmetic operations as well. Hope this code snippet helps:

        <assign fromexpr="$result/*:financeData/*:yearsCompounded/number()"
            outputvariable="yearsCompounded" />
        <assign fromexpr="$result/*:financeData/*:rate/number()"
            outputvariable="iRate" />
        <assign fromexpr="$iRate*$yearsCompounded" outputvariable="multiply"/>
        <display message="multiply::" variable="multiply"/>
      value in 'multiply' in this case is 0.01

Thanks,

Mythri

 

smitchell
smitchell's picture
User offline. Last seen 15 hours 15 min ago. Offline
Joined: 08/29/2008
Points: 34

number() does respect decimals so the format of your data should not be a problem.

How are you determining that number() is "skipping" past the data? Are you viewing it in Wires? Mashup Studio? or from the command line?

Sara, technical writer/jackbe

 

vanolind
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 07/17/2009
Points: 30

I'm debugging it using the Eclipse Plugin for Mashup studio.  Whenever I put "string()" as the function, the data reads from the document fine.  However whenever I put "number()"  it will not process the data.  Ive attached  some screenshots, perhaps that will help to narrow down the problem.  I have print outs of the mashup studio debugger "variables" tab open for both using the "string()" and "number()" function.

 

Thanks guys!

vanolind
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 07/17/2009
Points: 30

Never Mind I figured it out! It would just seem the variable checker in the mashup studio doesn't display numerical data, while it does show string data.  I had somthing else wrong with the code, and I thought it had to do with the variables because they wern't showing.

 

Thanks!

smitchell
smitchell's picture
User offline. Last seen 15 hours 15 min ago. Offline
Joined: 08/29/2008
Points: 34

Thanks for the update...

Sara, technical writer/jackbe

 

vanolind
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 07/17/2009
Points: 30

Thank you for helping me with my silly problems!