p5.js fract() Function Last Updated : 23 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The fract() function in p5.js is used to find the fractional part of a number. It can be mathematically represented as {x} where 'x' is the number. Syntax: fract( num ) Parameters: This function accepts single parameter as mentioned above and described below. num: This is a number of which the fractional part is to be found out. Return Value: It returns a number with the fractional part of the given number. Below example illustrates the fract() function in p5.js: Example: javascript function setup() { createCanvas(600, 200); textSize(22); text("Move the slider to observe the effects"+ " of the fract() function", 20, 30); sliderElem = createSlider(-5, 5, 0, 0.0001); sliderElem.position(20, 50); } function draw() { clear(); text("Move the slider to observe the"+ " effects of the fract() function", 20, 30); sliderVal = sliderElem.value(); // Find the fractional part of the number fractionalVal = fract(sliderVal); text("The slider value is: " + sliderVal, 20, 100); text("The fractional value is: " + fractionalVal, 20, 120); } Output: Online editor: https://editor.p5js.org/ Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/ Reference: https://p5js.org/reference/#/p5/fract Comment More infoAdvertise with us Next Article p5.js fract() Function S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js float() function The float() function in p5.js is used to get the floating point representation of the given string as a parameter. Syntax: float(String) Parameters: This function accepts a single parameter String which is used to be converted into its floating point representation. Return Value: It returns the conv 2 min read p5.js floor() function The floor() function in p5.js is used to calculate the floor value of a number. This function maps to the Math.floor() of javascript. It calculates the closest int value that is less than or equal to the value of the parameter. Syntax floor(number) Parameters: The function accepts only one parameter 1 min read p5.js abs() function The abs() function in p5.js is used to calculate the absolute value of a number. This function maps to the Math.abs() of javascript. A number's absolute value is always positive. Syntax abs(number) Parameters: The function accepts only one parameter as mentioned above and described below: number : T 1 min read p5.js char() function The char() function in p5.js is used to convert the given string or number value into its corresponding single-character string representation. If the input parameter is a string value then at first it gets converted into its integer equivalent internally after that its single-character string is re 3 min read p5.js byte() function The byte() function in p5.js is used to convert the given string of number, number value or boolean into its byte representation. This byte number can only be whole number in between -128 to 127. The value outside of the range is converted into its corresponding byte representation.Syntax:Â Â byte(Va 3 min read Like