In message <6819f2f8-7a9e-4ea4-a936-c4e00394b...@g28g2000yqh.googlegroups.com>,
vsoler wrote:
> I'm trying to print .7 as 70%
Just to be perverse:
(lambda x : (lambda s : s[:s.index(".")] + s[s.index(".") + 1:] +
"%")("%.2f" % x).lstrip("0"))(.7)
:)
--
http://mail.python.org/mailman/list
Hans Mulder wrote:
>> Did you try this:
>>
> print('%d%%' % (0.7 * 100))
>> 70%
>
>That method will always round down; TomF's method will round to
>the nearest whole number:
>
> >>> print "%d%%" % (0.698 * 100)
>69%
> >>> print "{0:.0%}".format(.698)
>70%
It was intended as a hint to this w
On Feb 22, 8:32 pm, Hans Mulder wrote:
> Günther Dietrich wrote:
> > vsoler wrote:
>
> >> I'm trying to print .7 as 70%
> >> I've tried:
>
> >> print format(.7,'%%')
> >> .7.format('%%')
>
> >> but neither works. I don't know what the syntax is...
>
> > Did you try this:
>
> print('%d%%' % (
Günther Dietrich wrote:
vsoler wrote:
I'm trying to print .7 as 70%
I've tried:
print format(.7,'%%')
.7.format('%%')
but neither works. I don't know what the syntax is...
Did you try this:
print('%d%%' % (0.7 * 100))
70%
That method will always round down; TomF's method will round to
vsoler wrote:
>I'm trying to print .7 as 70%
>I've tried:
>
>print format(.7,'%%')
>.7.format('%%')
>
>but neither works. I don't know what the syntax is...
Did you try this:
>>> print('%d%%' % (0.7 * 100))
70%
Best regards,
Günther
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 21, 7:11 pm, TomF wrote:
> On 2010-02-21 09:53:45 -0800, vsoler said:
>
> > I'm trying to print .7 as 70%
> > I've tried:
>
> > print format(.7,'%%')
> > .7.format('%%')
>
> > but neither works. I don't know what the syntax is...
> >>> print "Grade is {0:%}".format(.87)
>
> Grade is 87.000
On Feb 21, 5:53 pm, vsoler wrote:
> I'm trying to print .7 as 70%
> I've tried:
>
> print format(.7,'%%')
> .7.format('%%')
>
> but neither works. I don't know what the syntax is...
Assuming that you're using Python 2.6 (or Python 3.x):
>>> format(.7, '%')
'70.00%'
>>> format(.7, '.2%')
'70.
On 2010-02-21 09:53:45 -0800, vsoler said:
I'm trying to print .7 as 70%
I've tried:
print format(.7,'%%')
.7.format('%%')
but neither works. I don't know what the syntax is...
print "Grade is {0:%}".format(.87)
Grade is 87.00%
or if you want to suppress those trailing zeroes:
print
>>> print('%.0f%%' % (0.7*100))
70%
On Sun, Feb 21, 2010 at 12:53 PM, vsoler wrote:
> I'm trying to print .7 as 70%
> I've tried:
>
> print format(.7,'%%')
> .7.format('%%')
>
> but neither works. I don't know what the syntax is...
>
> Can you help?
>
> Thank you
> --
> http://mail.python.org/ma
I'm trying to print .7 as 70%
I've tried:
print format(.7,'%%')
.7.format('%%')
but neither works. I don't know what the syntax is...
Can you help?
Thank you
--
http://mail.python.org/mailman/listinfo/python-list
10 matches
Mail list logo