Changeset 248


Ignore:
Timestamp:
03/22/07 12:13:32 (7 years ago)
Author:
xi
Message:

Improve output of float values. Fix #49.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/representer.py

    r235 r248  
    198198            value = u'-.inf' 
    199199        else: 
    200             value = unicode(repr(data)) 
     200            value = unicode(repr(data)).lower() 
     201            # Note that in some cases `repr(data)` represents a float number 
     202            # without the decimal parts.  For instance: 
     203            #   >>> repr(1e17) 
     204            #   '1e17' 
     205            # Unfortunately, this is not a valid float representation according 
     206            # to the definition of the `!!float` tag.  We fix this by adding 
     207            # '.0' before the 'e' symbol. 
     208            if u'.' not in value and u'e' in value: 
     209                value = value.replace(u'e', u'.0e', 1) 
    201210        return self.represent_scalar(u'tag:yaml.org,2002:float', value) 
    202211 
Note: See TracChangeset for help on using the changeset viewer.