Comunidad de diseño web y desarrollo en internet online

Formateo de un TextBox

Citar            
MensajeEscrito el 03 Abr 2006 07:11 am
Hola amigos tengo este codigo:

Código :

class MiFormato
{
   function MiFormato ()
   {
      trace ("MiFormato inicializado!");
   }
   function format ()
   {
   var value : Number = arguments [ 0 ];
      var formattedValue:String = formatPrecision ( value, 2 );
      formattedValue = "$" + formattedValue;
      return formattedValue;
   }
   function formatPrecision ( num:Number, precision:Number, splitCharacter:String ) : String
   {
      var precision:Number = (precision = Math.abs(precision));
      if(  precision == 0 )
      {
         var returnValue = String ( Math.round(num) );
         return returnValue;
      }
      if ( splitCharacter == null )
      {
         splitCharacter = ".";
      }
      var returnValue:String = String  ( Math.floor(num) + splitCharacter + Math.floor(num * Math.pow( 10, precision)).toString().substr(-precision) );
      return addComma(returnValue);   
   }
  function addComma(n:String):String{
   var b = n.split(",")
   var c = int((b[0].length-1)/3)
   var d = ""
   for(var i=0, pos=b[0].length-3; i<=c; i++, pos-=3) {
      temp = ","+b[0].substr(pos, 3)
      d = temp+d
   }
   return d.substr(1)+","+b[1]
 }
} 

El resultado de este código me da esto: $305,.00,undefined.
Como puedo hacer para poder arreglar este AS, si alguien me puede ayudar, se lo agradeceria mucho.

Saludos

Por atomoclip

61 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 04 Abr 2006 06:16 pm
for(var i=0, pos=b[0].length-3; i<=c; i++, pos-=3) { temp = ","+b[0].substr(pos, 3) d = temp+d } <-- puede ser que el for esté mal escrito? las condiciones son sólo 3 miembros, al menos eso es lo que dice el help:

for(init; condition; next) {
statement(s);
}

Yo veo 4 en tu for....no? o es otra forma de escribirlo que yo no sé...

Por La_Gata

123 de clabLevel



 

msie

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.