a port of the Processing Visualization Language


int a=200, b=-40, c=90; 
String sa = nfp(a, 10); 
println(sa); // prints "+0000000200" 
String sb = nfp(b, 5); 
println(sb); // prints "-00040" 
String sc = nfp(c, 3); 
println(sc); // prints "+090" 
float d = -200.94, e = 40.2, f = -9.012; 
String sd = nfp(d, 10, 4); 
println(sd);  // prints "-0000000200.9400" 
String se = nfp(e, 5, 3); 
println(se);  // prints "+00040.200" 
String sf = nfp(f, 3, 5); 
println(sf);  // prints "-009.01200""
Description Utility function for formatting numbers into strings. Similar to nf() but puts a "+" in front of positive numbers and a "-" in front of negative numbers. 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.
nfp(intValue, digits)

nfp(floatValue, left, right)
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()

This reference is licensed under the CC BY-NC-SA 2.0 license:

Creative Commons License
Fork me on GitHub