5 Replies Latest reply on Jul 29, 2010 10:16 AM by ToddHanson

    automatic type conversion

    vikramswami
      Hi everyone,

      I am a newbie at flex and I was trying to write a small program which calls a .NET web service which returns the information in a xml format and the XML is returned to the Flex method. everything works fine but sometimes when the Data contains something like 122345E104, Flex converts this data into a numerical value automatically, because of the "E" it thinks it is an Exponential symbol. How can I prevent this from happenning.

      Eg if the data returned from the web service is as following

      <securityMasterByCusipResponse xmlns=" http://abc.com/RSSXSD/">
      <securityMasterByCusip>
      <masterList>
      <cusip>26144E101</cusip>
      <price>0.068</price>
      <symbol>DRGG</symbol>
      <securityName>DRAGON INTL GROUP</securityName>
      </masterList>
      </securityMasterByCusip>
      </securityMasterByCusipResponse>

      I have a method like this to read the data which is called as a callback to the aysnchronous web service call

      public function result(data:Object):void
      {
      var contentObject:Object = data.result.securityMasterByCusipResponse.securityMasterByCusip.masterList;
      cusipText.Text = Object.cusip; // this returns 2.61440000000000e+105 instead of 26144E101
      }

      Please help me to resolve this issue.

      Thanks in advance

      Regards
      Vikram
        • 1. Re: automatic type conversion
          VarioPegged Level 2
          Try setting the service's resultFormat to E4X. Adjust your result assignment accordingly:
          ...
          service.resultFormat = "e4x";
          service.send();
          ...
          var contentObject:Object = data.result.securityMasterByCusip.masterList;
          cusipText.text = contentObject.cusip;
          ...

          TS
          • 2. automatic type conversion
            vikramswami Level 1
            Hi Vario,

            Thanks for the reply.

            I have already tried that but it does not help.

            By the way I am using Cairngorm framework and the callback method
            which gets the response back from the web service is inside a command
            object.


            This is the class


            public class GetSecurityMasterByCusipCommand implements IResponder,
            ICommand
            {
            private var model : RSSModel = RSSModel.getInstance();
            public function execute(event : CairngormEvent) : void
            {
            var gde : DocumentDetailsEvent = event as DocumentDetailsEvent;
            var delegate : RSSDelegate = new RSSDelegate( this );
            delegate.getSecurityMasterByCusip(gde.request as
            SecurityMasterByCusipRequestVO);
            }


            /**
            * Result function. Used to get and process the response from
            * the server. Called by the Cairngorm framework.
            *
            * @param event
            */
            public function result(data:Object):void
            {
            var contentObject:Object =


            data.result.securityMasterByCusipResponse.securityMasterByCusip.masterList;
            model.cusip = Object.cusip; //This Model is used by the User
            Interface to populate the textbox
            //model.cusip shows the converted numeric value }



            }


            Regards
            Vikram
            • 3. Re: automatic type conversion
              ToddHanson

              Did you ever discover a solution for your exponential conversion issue?  I am running into the same problem for an app I'm writing which returns cusips to an advanceddatagrid that is displaying cusip's with an 'E' as exponential numbers.

               

              Thank You

              • 4. Re: automatic type conversion
                BhaskerChari Level 4

                Hi vikramswami,

                 

                Try to use the single quotes around that field...you can try this work around...

                 

                Check the below xml...the tag in bold...I have used single quotes around the value...so that it will be treated as a string instead of a numeric...

                 

                <securityMasterByCusipResponse xmlns=" http://abc.com/RSSXSD/">

                <securityMasterByCusip>

                <masterList>

                <cusip>'26144E101'</cusip>

                <price>0.068</price>

                <symbol>DRGG</symbol>

                <securityName>DRAGON INTL GROUP</securityName>

                </masterList>

                </securityMasterByCusip>

                </securityMasterByCusipResponse>

                 

                 

                So you need to strip the quotes while displaying the value in the Flex label or Text ...since we have appended these quotes in xml...

                 

                var contentObject:Object = data.result.securityMasterByCusipResponse.securityMasterByCusip.master List;
                model.cusip = Object.cusip; //This Model is used by the User

                model.cusip = model.cusip.substring(1,model.cusip.length-2);

                 

                Note: model.cusip variable should be a String datatyped variable...

                 

                 

                Hope this helps in resolving your problem.,..

                 

                 

                If this post answers your question or helps, please kindly mark it as such.


                Thanks,

                Bhasker Chari