你将使用什么来在Flex / AS3中填充一个数字? [英] What would you use to zero pad a number in Flex/AS3?

查看:181
本文介绍了你将使用什么来在Flex / AS3中填充一个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

复制 $ / b>

在Flex / AS3中,用什么填充0到左边的数字?



是否有相当于 printf 或者 NumberFormat 这样做?



我正在寻找这个或类似的最好的实现:

  public function zeroPad(number:int,width:int):String {
// number = 46,width = 4会返回0046
}

解决方案

  b $ b var ret:String =+ number; 
while(ret.length ret =0+ ret;
return ret;
}


Duplicate of this one.

What would you use to pad zeroes to the left of a number in Flex/AS3?

Is there an equivalent to printf or NumberFormat that does this?

I'm looking for the nicest implementation of this or something similar:

public function zeroPad(number:int, width:int):String {
    // number = 46, width = 4 would return "0046"
}

解决方案

public function zeroPad(number:int, width:int):String {
   var ret:String = ""+number;
   while( ret.length < width )
       ret="0" + ret;
   return ret;
}

这篇关于你将使用什么来在Flex / AS3中填充一个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆