4 Replies Latest reply on Aug 5, 2008 7:36 AM by Gregory Lafrance

    Substring Display Problem

    alice_data Level 1

      I have a scenario of where the database has quite a bit of long strings of numerical data, and I am wondering if it is possible that I can just substring it so that I get only the first five values excluding the decimal point when I print it out.

      Here is what I have now:
      <mx:Canvas id="data" label="Original Data" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
      <mx:DataGrid id="find" dataProvider="{rssRequest6.lastResult.one.beam}"
      labelFunction="lfnGeneral5" height="195" width="400">
      <mx:DataGridColumn headerText="ID" width="25" fontSize="8" />
      <mx:DataGridColumn headerText="Theta" width="95" fontSize="8" />
      <mx:DataGridColumn headerText="Phi" width="95" fontSize="8" />

      <mx:Text text="ID: {find2.selectedItem.id}" width="391" height="15" top="215"/>
      <mx:Text text="Theta: {find2.selectedItem.theta}" width="391" height="15" top="226"/>
      <mx:Text text="Phi: {find2.selectedItem.phi}" width="391" height="15" top="238"/>


      When the data prints out, I want only the four digits, while now it prints out 15 numbers all together in one string for each item. Is there some way which I can substring my text so that it only prints out no more than 2 places after the decimal point?

      Anything is appreciated.

        • 1. Re: Substring Display Problem
          Gregory Lafrance Level 6
          See this FB3 help topic:

          Using the standard formatters

          subsection: Formatting numbers

          precision property

          Number of decimal places to include in the output String.
          • 2. Re: Substring Display Problem
            if you create a function called something like firstFour and have that return the first four numbers of whatever you pass it the bind your text to that function it should work... ie:
            public function firstFour(num:Number):void {
            return (num as String).substr(0,3);

            <mx:Text text="Phi: {firstFour(find2.selectedItem.phi)}" width="391" height="15" top="238"/>

            Give that a crack... I haven't tested the code above but I have done this sort of thing before and it works great for formatting bound data
            • 3. Substring Display Problem
              alice_data Level 1

              It appears that the function brought back some other errors that tell me I cannot have an undefined var before a return clause is established.

              This is what I have in my clause:
              private function phi(data:Object, field:String, index:Number, percentValue:Number):String {
              var temp:String= ("Phi " + (index as String).substr(0,2));
              return temp;
              I then tried to call the function by using

              <mx:Text text="Phi: {phi(find2.selectedItem.phi)}" width="391" height="15" top="238"/>

              I was however returned with the following error:

              1136: Incorrect number of arguments. Expected 4.

              Is there some way I can fix this?

              • 4. Re: Substring Display Problem
                Gregory Lafrance Level 6
                I would use the NumberFormatter. They exist specifically for your purpose.