import math #numを小数第digit位まで残して、第digit位より下を切り捨てる def truncate_to_n_decimal(num, digit): return math.floor(num * 10 ** digit) / (10 ** digit) >>> truncate_to_n_decimal(1.234, 1) 1.2 >>> truncate_to_n_decimal(1.234, 2) 1.23例 1.234を小数第2で切り捨てる残したい位を小数点より左に移動させる 1.234 * 10**2 = 123.4小数点以下を切り捨てる math.floo…