The nfs() function in p5.js is used to format the input numbers (integers or floats) into strings as well as it adds ” ” (space) in front of positive input numbers and add negative (-) sign in front of negative input numbers. This function is used while aligning.
nfs(Num, Left, Right)
Parameters: This function accepts three parameters as mentioned above and described below:
- Num: This is the input positive number or an array of numbers which are to be formatted.
- Left: This is the positive number which says the number of digits should be on the left side of the decimal point.
- Right: This is the positive number which says the number of digits should be on the right side of the decimal point.
Return Value: It returns the formatted string.
Below programs illustrate the nfs() function in p5.js:
Example 1: This example uses nfs() function to format the input numbers and add single space in front of positive numbers to set align.
Example 2: This example uses nfs() function to format the input numbers and add space in front of positive numbers to set align.
- How to get the function name inside a function in PHP ?
- PHP | abs() Function
- p5.js | hex() function
- PHP | sin( ) Function
- p5.js | str() function
- CSS | url() Function
- p5.js | int() function
- D3.js | d3.map.set() Function
- PHP | Ds\Map get() Function
- CSS | hsl() Function
- D3.js | d3.max() function
- p5.js | red() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.