On Wed, Nov 26, 2008 at 9:59 AM, Greg <[EMAIL PROTECTED]> wrote: > > Hello, > I have the following code: > > /// > > b = Choice.objects.filter(choice=a.collection.id) > for cb in b: > discount_price = cb.price.name * Decimal(str(.75)) > cb.price.name = discount_price > assert False, cb.price.name > > /// > > Basically I'm just decreasing my price by 25%. However, when I do > this my new value contains 4 decimal places. 37.5000 or 135.0000. > What do I need to do to only show 2 decimal places. I know how to do > it in my template. But I need to be able to do this in my view. > > Thanks > > > > > This is more of a Python question, than a Django question. I do the following to print out only 2 decimal places from a float: >>> x = 35.0000 >>> print "%.2f" % x 35.00
You can use float() instead of print to get a float type back, but that is probably not the most efficient way to do things. -- Best, R --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

