你会用什么来在 Flex/AS3 中对数字进行零填充? [英] What would you use to zero pad a number in Flex/AS3?

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

问题描述

重复这个 一个.

Duplicate of this one.

在 Flex/AS3 中,您会使用什么将零填充到数字的左侧?

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

是否有与 printfNumberFormat 等效的方法来执行此操作?

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天全站免登陆