[Tutor] float & string

Lloyd Kvam pythontutor@venix.com
Wed, 29 May 2002 17:51:56 -0400


 >        accountcurrents.xlamount = "%.2f%s" % (abs(accountcurrents.xlamount), char) #here the - gets added, and it becomes a string
%.2f will show two decimal places
You may not need to use round depending upon what else happens to xlamount.


Terje Johan Abrahamsen wrote:

> I have a floating number (240.00) that I want to make into a string, so 
> I can add a character to the end of it. But, the string doesn't become 
> 240.00, but 240.000000. How can I make sure that the string stays like a 
> dollar amount?
> 
> Thanks in advance,
> Terje
> 
> ------
> Here is a part of the code:
> 
> a = accountcurrents.xlamount # the stringvar with the dollar amount.
>        accountcurrents.xlamount = string.atof(a) #conv to float
>        round(accountcurrents.xlamount, 2) #round to 2 digits
>        if accountcurrents.xlamount < 0: #if negative add '-' behind
>            char = '-'
>        else:
>            char = ''
> 
>        accountcurrents.xlamount = "%f%s" % 
> (abs(accountcurrents.xlamount), char) #here the - gets added, and it 
> becomes a string
> 
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582