Reference for Processing version 1.2. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

nfs()

Examples
int a=200, b=-40, c=90; 
String sa = nfs(a, 10); 
println(sa); // prints " 0000000200" 
String sb = nfs(b, 5); 
println(sb); // prints "-00040" 
String sc = nfs(c, 3); 
println(sc); // prints " 090" 
 
float d = -200.94, e = 40.2, f = -9.012; 
String sd = nfs(d, 10, 4); 
println(sd);  // prints "-0000000200.9400" 
String se = nfs(e, 5, 3); 
println(se);  // prints " 00040.200" 
String sf = nfs(f, 3, 5); 
println(sf);  // prints "-009.01200"
Description Utility function for formatting numbers into strings. Similar to nf() but leaves a blank space in front of positive numbers so they align with negative numbers in spite of the minus symbol. 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.
Syntax
nfs(intValue, digits)
nfs(floatValue, left, right)
Parameters
intValue int or int[]: the number(s) to format
digits int: number of digits to pad with zeroes
floatValue float or float[]: the number(s) to format
left int: number of digits to the left of the decimal point
right int: number of digits to the right of the decimal point
Returns String or String[]
Usage Web & Application
Related nf()
nfp()
nfc()
Updated on June 14, 2010 12:05:29pm EDT

Creative Commons License