Django

Code

Show
Ignore:
Timestamp:
11/11/08 18:35:24 (2 months ago)
Author:
kmtracey
Message:

Fixed #5079 -- Avoid converting Decimals to floats during save to the database.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/util.py

    r8193 r9394  
    125125    decimal places. 
    126126    """ 
    127     return u"%.*f" % (decimal_places, value) 
     127    if isinstance(value, decimal.Decimal): 
     128        context = decimal.getcontext().copy() 
     129        context.prec = max_digits 
     130        return u'%s' % str(value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)) 
     131    else: 
     132        return u"%.*f" % (decimal_places, value)