Sha256: 2c539821940695bf30c7175623da6b6b8b15723d235f279a4d4bf32a5ae4a3cb
Contents?: true
Size: 892 Bytes
Versions: 119
Compression:
Stored size: 892 Bytes
Contents
require 'yaml' require 'bigdecimal' require 'rubygems' require 'active_support' class BigDecimal yaml_as "tag:yaml.org,2002:float" def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) do |out| # This emits the number without any scientific notation. # I prefer it to using self.to_f.to_s, which would loose precision. # # Note that YAML allows that when reconsituting floats # to native types, some precision may get lost. # There is no full precision real YAML tag that I am aware of. str = self.to_s if str == "Infinity" str = ".Inf" elsif str == "-Infinity" str = "-.Inf" elsif str == "NaN" str = ".NaN" end out.scalar( "tag:yaml.org,2002:float", str, :plain ) end end end
Version data entries
119 entries across 119 versions & 1 rubygems