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

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

问题描述

有没有把数字如1234.5678分成两部分(1234,0.5678),即整数部分和小数部分的pythonic方式?

解决方案

 导入数学
x = 1234.5678
math.modf(x)#(0.5678000000000338,1234.0)


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

解决方案

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

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

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