2 Replies Latest reply on May 25, 2006 7:01 AM by Alexander_Fabian

    Problem with decimal...

    Alexander_Fabian
      The last part of my code is:

      quote:

      onEnterFrame = function () {
      totaleuro.text = String(Number(quant.text)*Number(euro.text));
      totaldolar.text = String(Number(quant.text)*Number(dolar.text));
      totalpound.text = String(Number(quant.text)*Number(pound.text));
      totalyen.text = String(Number(quant.text)*Number(yen.text));
      };


      The problem is that results has a lot of digits and I need only two (cents). I tried to do the following thing:

      quote:

      onEnterFrame = function () {
      totaleuro.text = String((Number(quant.text)*Number(euro.text))*100);
      totaldolar.text = String((Number(quant.text)*Number(dolar.text))*100);
      totalpound.text = String((Number(quant.text)*Number(pound.text))*100);
      totalyen.text = String((Number(quant.text)*Number(yen.text))*100);
      //...
      Math.round((totaleuro.text)/100);
      Math.round((totaldolar.text)/100);
      Math.round((totalpound.text)/100);
      Math.round((totalyen.text)/100);


      ... But that not function ...

      How I can to get a value as nn,nn?...

      Thanks!...
        • 1. Re: Problem with decimal...
          blemmo Level 1
          You have the right formula to do this, but it's not used right: you're calculating with a string, and the result isn't used anywhere. Try this:
          totaleuro.text = String( Math.round( Number(quant.text)*Number(euro.text)*100 ) / 100 );

          hth,
          blemmo
          • 2. Re: Problem with decimal...
            Alexander_Fabian Level 1
            ...
            quote:

            You have the right formula to do this, but it's not used right: you're calculating with a string, and the result isn't used anywhere. Try this:
            totaleuro.text = String( Math.round( Number(quant.text)*Number(euro.text)*100 ) / 100 );

            hth,
            blemmo


            Thank you very much Blemmo... This is a correct setting of code.