将数字分为整数和小数部分 [英] splitting a number into the integer and decimal parts

查看:64
本文介绍了将数字分为整数和小数部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在将诸如1234.5678之类的数字分为两个部分(1234, 0.5678)(即整数部分和小数部分)的pythonic方法?

Is there a pythonic way of splitting a number such as 1234.5678 into two parts (1234, 0.5678) i.e. the integer part and the decimal part?

推荐答案

使用 math.modf :

import math
x = 1234.5678
math.modf(x) # (0.5678000000000338, 1234.0)

这篇关于将数字分为整数和小数部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆