Name |
nf()格式化成字符串 |
||||||||||
Examples |
int a=200, b=40, c=90; String sa = nf(a, 10); println(sa); // Prints “0000000200” String sb = nf(b, 5); println(sb); // Prints “00040” String sc = nf(c, 3); println(sc); // Prints “090”
float d = 200.94, e = 40.2, f = 9.012; String sd = nf(d, 10, 4); println(sd); // Prints “0000000200.9400” String se = nf(e, 5, 3); println(se); // Prints “00040.200” String sf = nf(f, 3, 5); println(sf); // Prints “009.01200” |
||||||||||
Description |
Utility function for formatting numbers into strings. There are two versions: one for formatting floats, and one for formatting ints. The values for the digits, left, and right parameters should always be positive integers. As shown in the above example, nf() is used to add zeros to the left and/or right of a number. This is typically for aligning a list of numbers. To remove digits from a floating-point number, use the int(), ceil(), floor(), or round() functions. 用于将数字格式化为字符串的实用程序函数。有两个版本: 一个用于格式化浮动, 一个用于格式化整数。数字、左和右参数的值应始终为正整数。
如上例所示, nf () 用于在数字的左边和/或右边添加零。这通常用于对齐数字列表。若要从 floating-point 数字中移除数字, 请使用 int ()、天花板 ()、底板 () 或圆形 () 函数。 |
||||||||||
Syntax |
nf(num) nf(nums) nf(nums, digits) nf(num, digits) nf(nums, left, right) nf(num, left, right) |
||||||||||
Parameters |
|
||||||||||
Returns |
String[] |
||||||||||
Related |
nfs() |
- 本文固定链接: http://iprocessing.cn/2017/07/21/nf格式化成字符串/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表