import yaml


def yaml_dump_result(obj, stream):
    """Redefinition of yaml.safe_dump with added float representer

    The float representer uses float precision of four decimal digits
    """
    def float_representer(dumper, value):
        text = '{0:.4f}'.format(value)
        return dumper.represent_scalar(u'tag:yaml.org,2002:float', text)

    class ResultDumper(yaml.SafeDumper):
        def __init__(self, *args, **kwargs):
            super(ResultDumper, self).__init__(*args, **kwargs)
            self.add_representer(float, float_representer)

    yaml.dump(obj, stream, Dumper=ResultDumper, default_flow_style=False, sort_keys=True)