On Thursday, January 9, 2014 7:37:43 AM UTC+11, Timothy W. Cook wrote:
>
>
> On Wed, Jan 8, 2014 at 6:07 PM, Erik Cederstrand 
> <[email protected]<javascript:>
> > wrote:
>
>> Den 08/01/2014 kl. 17.56 skrev Daniel Roseman 
>> <[email protected]<javascript:>
>> >:
>>
> <snip> 

> >
>> But to post the solution to the issue, just for completeness. 
>>
>
> Yes, Django does store the field contents as decimal.Decimal objects.  In 
> your templates or if writing out to a file (as I need to do) you need to 
> use the formatting option. 
>
> Example using the previously used model field:
>
> str('%.10g' % self.min_inclusive).strip()
>   
> This removes all non-significant zeros. So it gives me '0' for a zero.  
>

I use a slightly different approach to chop unwanted zeroes ...

def chop_zeros(val):
    if isinstance(val, decimal.Decimal):
        return float(val)
    return val

... which I call for *all* numeric values before I do any string 
formatting. Which is why it works for me.

Mike


 

>
>
> -- 
> MLHIM VIP Signup: http://goo.gl/22B0U
> ============================================
> Timothy Cook, MSc           +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2207740c-d3ca-4998-a834-6f146231a4cd%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to