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. |
||||||||||
Syntax | nf(intValue, digits) nf(floatValue, left, right) |
||||||||||
Parameters |
|
||||||||||
Returns | String or String[] | ||||||||||
Usage | Web & Application | ||||||||||
Related |
nfs() nfp() nfc() |