Methods
Constants
DEFAULT_STRING_FORMAT | = | 'F'.freeze |
YAML_TAG | = | 'tag:yaml.org,2002:float'.freeze |
YAML_MAPPING | = | { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } |
Public Instance methods
[ show source ]
# File activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb, line 20 20: def to_formatted_s(format = DEFAULT_STRING_FORMAT) 21: _original_to_s(format) 22: end
This emits the number without any scientific notation. This is better than self.to_f.to_s since it doesn‘t lose precision.
Note that reconstituting YAML floats to native floats may lose precision.
[ show source ]
# File activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb, line 28 28: def to_yaml(opts = {}) 29: YAML.quick_emit(nil, opts) do |out| 30: string = to_s 31: out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain) 32: end 33: end