将整数转换为字符串 as3

发布于 2024-08-21 04:01:32 字数 3708 浏览 3 评论 0原文

如何将整数转换为字符串值? 这一定很容易。 “SO里的你们最擅长解释。”我仍在研究这些愚蠢的计数器。

需要加入到一起

//My counter project "sends to dynamic text field"
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  


function incrementCounter(event:TimerEvent) {  
  count++;  
  //
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  //
  var whole_value:int = int(fcount / 100); //change value 
  var tenths:int = int(fcount / 10) % 10;   
  var hundredths:int = int(fcount) % 10;   

  mytext.text = whole_value + " : " + tenths + hundredths;  
} 

ZEROS PLACEHOLDER

//Code for adding "zero placeholders"
function formatCount(i:int):String { 

    var fraction:int = i % 100; 
    var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction; 
} 

function test():void { 
    for (var i:int = 1; i<100000; i += 3) { 
        trace(i + " -> " + formatCount(i)); 
    } 
} 

获取未定义属性的访问权限,myInt.toString();

//joined together
    var timer:Timer = new Timer(10);  
    var count:int = 0; //start at -1 if you want the first decimal to be 0  
    var fcount:int = 0; 

    timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
    timer.start();  



     myInt.toString();
    function incrementCounter(event:TimerEvent) {  
      count++;  
      //
      fcount=int(count*count/10000);//starts out slow... then speeds up 
      //
      var whole_value:int = int(fcount / 100); //change value 
      var tenths:int = int(fcount / 10) % 10;   
      var hundredths:int = int(fcount) % 10;   

      mytext.text = whole_value + " : " + tenths + hundredths;  
    }   

    function formatCount(i:int):String {  

        var fraction:int = i % 100;  
        var whole:int = i / 100;  

        return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction;  
    }  

    function test():void {  
        for (var i:int = 1; i<100000; i += 3) {  
            trace(i + " -> " + formatCount(i));  
        }  
    } 

现在没有错误,以其他方式破坏它

var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  

function incrementCounter(event:TimerEvent) {  
  count++;  
  //
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  //
  var whole_value:int = int(fcount / 100); //change value 
  var tenths:int = int(fcount / 10) % 10;   
  var hundredths:int = int(fcount) % 10;   
////////////// 
 function formatCount(i:int):String { 

    var fraction:int = i % 100; 
    var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction; 
} 

function test():void { 
    for (var i:int = 1; i<100000; i += 3) { 
        trace(i + " -> " + formatCount(i)); 
    } 
} 
//////////////
mytext.text = formatCount(whole_value + " : " + tenths + hundredths); 

 // mytext.text = whole_value + " : " + tenths + hundredths;  
}

示例

// string to number
var myString:String = "5";
var myNumber:Number = Number(myString);

// number to string
var myNumber:Number= 5;
var myString:String= String(myNumber);

// string to int (integer)
var myString:String = "5";
var myInt:int = int(myString);

How do I convert an integer to a string value?
This must be easy. "Ya guys in SO are da best at explaining." I'm still working on these dumb counters.

NEED TO JOIN THIS TOGETHER

//My counter project "sends to dynamic text field"
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  


function incrementCounter(event:TimerEvent) {  
  count++;  
  //
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  //
  var whole_value:int = int(fcount / 100); //change value 
  var tenths:int = int(fcount / 10) % 10;   
  var hundredths:int = int(fcount) % 10;   

  mytext.text = whole_value + " : " + tenths + hundredths;  
} 

ZEROS PLACEHOLDER

//Code for adding "zero placeholders"
function formatCount(i:int):String { 

    var fraction:int = i % 100; 
    var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction; 
} 

function test():void { 
    for (var i:int = 1; i<100000; i += 3) { 
        trace(i + " -> " + formatCount(i)); 
    } 
} 

Getting access of undefined property, myInt.toString();

//joined together
    var timer:Timer = new Timer(10);  
    var count:int = 0; //start at -1 if you want the first decimal to be 0  
    var fcount:int = 0; 

    timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
    timer.start();  



     myInt.toString();
    function incrementCounter(event:TimerEvent) {  
      count++;  
      //
      fcount=int(count*count/10000);//starts out slow... then speeds up 
      //
      var whole_value:int = int(fcount / 100); //change value 
      var tenths:int = int(fcount / 10) % 10;   
      var hundredths:int = int(fcount) % 10;   

      mytext.text = whole_value + " : " + tenths + hundredths;  
    }   

    function formatCount(i:int):String {  

        var fraction:int = i % 100;  
        var whole:int = i / 100;  

        return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction;  
    }  

    function test():void {  
        for (var i:int = 1; i<100000; i += 3) {  
            trace(i + " -> " + formatCount(i));  
        }  
    } 

NO ERROR NOW, BROKE IT SOME OTHER WAY

var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  

function incrementCounter(event:TimerEvent) {  
  count++;  
  //
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  //
  var whole_value:int = int(fcount / 100); //change value 
  var tenths:int = int(fcount / 10) % 10;   
  var hundredths:int = int(fcount) % 10;   
////////////// 
 function formatCount(i:int):String { 

    var fraction:int = i % 100; 
    var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" : "") + fraction; 
} 

function test():void { 
    for (var i:int = 1; i<100000; i += 3) { 
        trace(i + " -> " + formatCount(i)); 
    } 
} 
//////////////
mytext.text = formatCount(whole_value + " : " + tenths + hundredths); 

 // mytext.text = whole_value + " : " + tenths + hundredths;  
}

EXAMPLES

// string to number
var myString:String = "5";
var myNumber:Number = Number(myString);

// number to string
var myNumber:Number= 5;
var myString:String= String(myNumber);

// string to int (integer)
var myString:String = "5";
var myInt:int = int(myString);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

伴随着你 2024-08-28 04:01:32

myInt.toString();

myInt.toString();

银河中√捞星星 2024-08-28 04:01:32

我的印象是 AS3 有一个 String() 方法,它将显式地将数字类型的变量强制转换为字符串。整数可以很容易地转换为数字,而且我很确定在这种情况下它会隐式完成。

text = String(number);

I was under the impression AS3 has a String() method which will explicitly coerce a variable of the type number into a String. Integers can be converted to numbers easily enough, and i'm pretty sure it would be done implicitly in this case.

text = String(number);
还给你自由 2024-08-28 04:01:32

我使用 5 + "" ,任何时候添加 "" (无字符),它都会将任何内容转换为字符串,并且很容易记住。

I use 5 + "", any time you add "" (no character) , it converts anything to a string and it's easy to remember.

短暂陪伴 2024-08-28 04:01:32

计数器“动态文本”与零值解决方案
我代表 Ed 发帖,他是通过电话帮助我的人。这是 mytext 中字符串参数和语法的问题。

//CA, NC, LONDON, ED "increments"
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  

function incrementCounter(event:TimerEvent) {  
  count++;  
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  mytext.text = formatCount(fcount);
}

function formatCount(i:int):String { 
     var fraction:int = i % 100; 
     var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction); 
} 

COUNTER "DYNAMIC TEXT" with zero values solution
I'm posting on behalf of Ed, a human that helped me over the phone. It was a problem with the string arguments and the syntax in mytext.

//CA, NC, LONDON, ED "increments"
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  

function incrementCounter(event:TimerEvent) {  
  count++;  
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  mytext.text = formatCount(fcount);
}

function formatCount(i:int):String { 
     var fraction:int = i % 100; 
     var whole:int = i / 100; 

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction); 
} 
不如归去 2024-08-28 04:01:32

很简单==>

var myint:int = 500;
var myintToString:String = myint+"";

very simple ==>

var myint:int = 500;
var myintToString:String = myint+"";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文