math.modf介绍
math.modf返回一个数值的整数与小数部分,如果这个数值是整数,那么返回的小数部分就是0.0。
返回的两个值的符号与参数的符号是一样的,即参数是负值返回的两个值也是负值,参数是正值返回的两个值也是正值。
math.modf使用
如下代码:
print(string.format("math.modf(2) is %s + %s", math.modf(2)))
print(string.format("math.modf(2.3) is %s + %s", math.modf(2.3)))
print(string.format("math.modf(math.huge) is %s + %s", math.modf(math.huge)))
print(string.format("math.modf(3/4) is %s + %s", math.modf(3/4)))
输出如下:
math.modf(2) is 2 + 0.0
math.modf(2.3) is 2 + 0.3
math.modf(math.huge) is inf + 0.0
math.modf(3/4) is 0 + 0.75
math.modf总结
math.modf把参数分解为整数与小数部分,返回的这两个值符号与参数的符号是一样的。