将浮动比率转换为int [英] Converting floating ratios to int

查看:89
本文介绍了将浮动比率转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将浮动比率转换为它们的整数等效值

I need to convert float ratios to their integer equivalent

0.5:1 ---应该转换为---> 1:2

0.5:1 ---should convert to ---> 1:2

0.5:0.6:1 ---应转换为---> 5:6:10(最小整数比)

0.5:0.6:1 ---should convert to ---> 5:6:10 (smallest integer ratio)

我的谷歌搜索在这方面没有任何结果

My googling produced no results in this regard

推荐答案

float.as_integer_ratio:

In [1064]: f = .5                                                                                                                                                                                           

In [1065]: f.as_integer_ratio()                                                                                                                                                                             
Out[1065]: (1, 2)

这篇关于将浮动比率转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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