9 Replies Latest reply on Jun 13, 2007 8:52 AM by Newsgroup_User

    Converting Integers to Strings

      Hi all,

      I'm trying to convert an integer value into a string so that I can then manipulate the individual characters and am having problems! My current code is something like the below:

      _global.hundreds = 0;
      _global.tens = 0;
      _global.units = 0;
      _global.tenps = 0;
      _global.unitps = 0;
      _global.credits = "";

      var money = 542.19;
      var credStr:String = "";

      credStr = money;

      _global.credits = credStr;

      I don't know if it's necessary or not, but I used local variables to pass the information into the _global variable as I wasn't sure if I could specify the data type in a _global variable?!

      Suffice to say, this isn't working. It doesn't seem to want to convert the number into a string whatever I do!

      FYI the following code is what is supposed to happen to the string once it is converted:

      if (_global.credits.length < 6) {
      if (_global.credits.length == 5) {
      _global.credits = "0"+_global.credits;
      else if (_global.credits.length == 4) {
      _global.credits = "00"+_global.credits;

      var fc:String = _global.credits.charAt(0);
      var sc:String = _global.credits.charAt(1);
      var tc:String = _global.credits.charAt(2);
      var fc2:String = _global.credits.charAt(4);
      var sc2:String = _global.credits.charAt(5);


      _global.hundreds = (fc);
      _global.tens = (sc);
      _global.units = (tc);
      _global.tenps = (fc2);
      _global.unitps = (sc2);

      I have tested this by passing the value in as a string in the first place and it works perfectly - so it's just the conversion where I am not getting this right :(

      Any help with this would be greatly appreciated!

      Thanks, Richard