p5.js中的round()函數用於計算數字的取整值。它計算最接近該數字的整數。
用法
round(number)
參數:該函數僅接受如上所述和以下描述的一個參數:
- number:此參數存儲要計算的數字。
以下示例程序旨在說明p5.js中的round()函數:
例:
function setup() {
//create Canvas of size 270*80
createCanvas(270, 80);
}
function draw() {
background(220);
//initialize the parameter
let x = 67.54;
//call to round() function
let y = round(x);
textSize(16);
fill(color('red'));
text("Given Number is : " + x, 50, 30);
text("Computed Number is : " + y, 50, 50);
}
輸出:
參考: https://p5js.org/reference/#/p5/round
相關用法
- PHP round( )用法及代碼示例
- Javascript Math.round( )用法及代碼示例
- Javascript Math.round( )用法及代碼示例
- p5.js red()用法及代碼示例
- p5.js arc()用法及代碼示例
- CSS var()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js int()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 p5.js | round() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。