Malcom,

This seems so obvious, I'm working on an invoice system and already passed the 
chapter on rounding decimals. I still am somewhat overwhelmed I guess by all 
that Django does. Nevertheless, it's impressive how good Django keeps to 
(python) conventions.

Thanx a lot.

Regards,

Gerard.


Malcolm Tredinnick wrote:
> 
> On Sat, 2008-09-27 at 18:07 +0200, Gerard Petersen wrote:
>> Dear Django team,
>>
>> It seems, but since I'm human it could be me, that in a modelform with a 
>> forms.DecimalField declaration the min_value is not picked up when it has 
>> decimals in it. The snippet:
>>
>>     per_price = forms.DecimalField(
>>                             label='Per Price',
>>                             min_value=0.01,
>>                             decimal_places=2
>>                             )
>>
>> I want to force a 'value > 0'. A value of '1' works but that defies the 
>> purpose of having 2 decimal_places. Note: a value of 0.01 for "initial=.." 
>> does work.
> 
> It's kind of a small inconsistency that a float is allowed for an
> initial value there. The fact is, this is a DecimalField, so using
> floats is something you should avoid doing. In Python, the following
> holds:
> 
>         >>> Decimal('0.05') < 0.1
>         False
> 
> In other words, decimals and floats do not compare as you might expect
> (since you cannot reliably convert a float to an exact decimal value).
> 
> Instead, you should be passing in a Decimal instance for the minimum
> value:
> 
>         min_val = Decimal('0.01')
>         
> and then it will work. Internally, Django has already converted the
> input value to a Decimal instance and is then using '<' and '>' to
> compare against min_value and max_value, so it needs to be comparing
> similar types.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 

-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to