def draw
background(200)
# map, mouseX between 0 and 5.
ax = map(mouseX, 0, 100, 0, 5)
ay = 66
# Round the mapped number.
bx = round(map(mouseX, 0, 100, 0, 5))
by = 33
# Multiply the mapped numbers by 20 to more easily
# see the changes.
stroke(0)
fill(0)
line(0, ay, ax * 20, ay)
line(0, by, bx * 20, by)
# Reformat the float returned by map and draw it.
noStroke
text(format("%.2f", ax), ax, ay - 5)
text(format("%.1f", bx), bx, by - 5)
end
四捨五入した値を計算します。
| 引数名 | 内容 | 備考 | オプション | デフォルト値 |
|---|---|---|---|---|
| n | 数値 | |||
| decimals | 小数点以下桁数 | ○ | 0 |
r : 四捨五入された値