Static p5_sys::global::nf [−][src]
pub static nf: NfInternalType
Expand 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. (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter if greater than the current length of the number. For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123 (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than the result will be 123.200.
Examples
let myFont; function preload() { myFont = loadFont('assets/fonts/inconsolata.ttf'); } function setup() { background(200); let num1 = 321; let num2 = -1321; noStroke(); fill(0); textFont(myFont); textSize(22); text(nf(num1, 4, 2), 10, 30); text(nf(num2, 4, 2), 10, 80); // Draw dividing line stroke(120); line(0, 50, width, 50); }
Overloads
num
the Number to format
left?
number of digits to the left of the
decimal point
right?
number of digits to the right of the
decimal point
nums
the Numbers to format
left?
number of digits to the left of the
decimal point
right?
number of digits to the right of the
decimal point