近似的数字 [英] aproximate a number

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

问题描述

大家好。我需要将给定的浮点数近似为下一个(int)

更大的浮点数。由于我的英语不好,我试着用一些例子来解释它:


5.7 - > 6

52.987 - > 53

3.34 - > 4

2.1 - > 3

问候

Hi all. I''d need to aproximate a given float number into the next (int)
bigger one. Because of my bad english I try to explain it with some example:

5.7 --> 6
52.987 --> 53
3.34 --> 4
2.1 --> 3

Regards

推荐答案

billiejoex写道:
billiejoex wrote:
大家好。我需要将给定的浮点数近似为下一个(int)
更大的浮点数。由于我的英语不好,我试着用一些例子来解释它:

5.7 - > 6
52.987 - > 53
3.34 - > 4
2.1 - > 3


Hi all. I''d need to aproximate a given float number into the next (int)
bigger one. Because of my bad english I try to explain it with some example:

5.7 --> 6
52.987 --> 53
3.34 --> 4
2.1 --> 3

Regards




math.ceil返回你需要的但是作为一个浮点数,然后创建一个int



math.ceil returns what you need but as a float, then create an int

import math
math.ceil(12.3)
13.0 int(math.ceil(12.3))
import math
math.ceil (12.3) 13.0 int (math.ceil (12.3))



13

hth


-

rafi


想象力比知识更重要。

(阿尔伯特爱因斯坦)


13

hth

--
rafi

"Imagination is more important than knowledge."
(Albert Einstein)


billiejoex写道:
billiejoex wrote:
大家好。我需要将给定的浮点数近似为下一个(int)
更大的浮点数。由于我的英语不好,我试着用一些例子来解释它:

5.7 - > 6
52.987 - > 53
3.34 - > 4
2.1 - > 3
Hi all. I''d need to aproximate a given float number into the next (int)
bigger one. Because of my bad english I try to explain it with some example:

5.7 --> 6
52.987 --> 53
3.34 --> 4
2.1 --> 3




看看math.ceil



Have a look at math.ceil

导入数学
math.ceil(5.7)
import math
math.ceil(5.7)





将McGugan

-
http://www.willmcgugan.com

"" .join({''*'':''@'',''^'':''。''}。get(c,0)或chr(97+ (ord(c)-84)%26)for c in

" jvyy * jvyyzpthtna ^ pbz")


6.0
Will McGugan
--
http://www.willmcgugan.com
"".join({''*'':''@'',''^'':''.''}.get(c,0) or chr(97+(ord(c)-84)%26) for c in
"jvyy*jvyyzpthtna^pbz")


billiejoex写道:
billiejoex wrote:
大家好。我需要将给定的浮点数近似为下一个(int)
更大的浮点数。由于我的英语不好,我试着用一些例子来解释它:

5.7 - > 6
52.987 - > 53
3.34 - > 4
2.1 - > 3
Hi all. I''d need to aproximate a given float number into the next (int)
bigger one. Because of my bad english I try to explain it with some example:

5.7 --> 6
52.987 --> 53
3.34 --> 4
2.1 --> 3




可能类似于int(数字+ 0.99999999),具体取决于你想要的

边界情况(你没有提到过)从技术上讲,

它应该是int(数字+ 1.0 - epsilon)。


-

Erik Max Francis& ;& ma*@alcyone.com && http://www.alcyone.com/max/

美国加利福尼亚州圣何塞&& 37 20 N 121 53 W& AIM erikmaxfrancis

如果你害怕寂寞,不要结婚。

- Anton Chekhov



Probably something like int(number + 0.99999999), depending on the
boundary cases you want (which you haven''t mentioned here. Technically,
it should be int(number + 1.0 - epsilon).

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
If you are afraid of loneliness, do not marry.
-- Anton Chekhov


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

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