1 2 3 4 5 6 7 8 | -- 四捨五入。実数numを、小数idp桁で丸める。 function math.round(num, idp) if idp and idp>0 then local mult = 10^idp return math.floor (num * mult + 0.5) / mult end return math.floor (num + 0.5) end |
1 2 3 4 5 6 7 | -- 対象の引数が整数かどうかの判定 function math.is_integer(num) if type (num) == "number" then return num%1 == 0 end return false end |
1 2 3 4 | -- 対象の引数の整数を16進の文字列に変換します。 function math.hex(num) return string.format ( "%x" , num) end |