浮动数字和str [英] Floating numbers and str
本文介绍了浮动数字和str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将浮动变量限制为4个有意义的数字,当
运行strugh a str命令时。 Ei,
x = .13241414515
y = str(x)+"这里的东西
但不知何故将其限制在4个符号。数字。我知道如果你使用
打印语句,你可以做类似%.4d的事情,但是如何将这个数字转换为字符串?
?谢谢!
I would like to limit a floating variable to 4 signifigant digits, when
running thorugh a str command. Ei,
x=.13241414515
y=str(x)+" something here"
But somehow limiting that to 4 sign. digits. I know that if you use the
print statement, you can do something like %.4d, but how can I do this
with converting the number to a string? Thanks!
推荐答案
Tuvas写道:
我想将浮动变量限制为4个有意义的数字,当
运行strugh一个str命令。 Ei,
x = .13241414515
y = str(x)+"这里有什么东西
但不知何故将它限制为4个符号。数字。我知道如果你使用
print语句,你可以做类似%.4d的事情,但是如何将数字转换为字符串呢?谢谢!
I would like to limit a floating variable to 4 signifigant digits, when
running thorugh a str command. Ei,
x=.13241414515
y=str(x)+" something here"
But somehow limiting that to 4 sign. digits. I know that if you use the
print statement, you can do something like %.4d, but how can I do this
with converting the number to a string? Thanks!
浮点型
%d?是吗?
无论如何,ITYW:
"%。4g" %x
例如:
%d for a floating-point type? Is that right?
Anyway, ITYW:
"%.4g" % x
E.g:
x = .13241414515
y ="%。4g这里的东西 %x
打印y
0.1324这里的东西
x=.13241414515
y="%.4g something here" % x
print y 0.1324 something here
我想你回答了自己的问题。 :)
x = 0.12345678
y ="%。4f something here" %x
在星期三,2005-11-09 11:52 - 0800,Tuvas写道:
I think you answered your own question. :)
x = 0.12345678
y = "%.4f something here" % x
On Wed, 2005-11-09 at 11:52 -0800, Tuvas wrote:
我想将浮动变量限制为4
运行strugh命令时,有意义的数字。 Ei,
x = .13241414515
y = str(x)+"这里有什么东西
但不知何故将它限制为4个符号。数字。我知道如果你使用
print语句,你可以做类似%.4d的事情,但是如何将数字转换为字符串呢?谢谢!
I would like to limit a floating variable to 4 signifigant digits, when
running thorugh a str command. Ei,
x=.13241414515
y=str(x)+" something here"
But somehow limiting that to 4 sign. digits. I know that if you use the
print statement, you can do something like %.4d, but how can I do this
with converting the number to a string? Thanks!
是的,我在想C,而不是python。谢谢你的帮助!
Yep, I was thinking in C, not python. Thanks for the help!
这篇关于浮动数字和str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文