*Luaで良く作る関数 ~math編~ [#ke1f7d22]

-[[math.round>#math_round]]
-[[math.isinteger>#math_isinteger]]

&aname(math_round);
**math.round [#zf0d6a34]
#sh(lua){{
-- 四捨五入。実数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
}}

&aname(math_isinteger);
**math.isinteger [#u90e429f]
#sh(lua){{
-- 対象の引数が整数かどうかの判定
function math.isinteger(num)
    if type(num) ~= "number" then return false end
    return num%1 == 0
end
}}

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS