Class: Plumb::Codec::DecimalEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/plumb/codec.rb

Overview

BigDecimal <=> canonical decimal string ("1.5"). A string, not a number: decimals exist to avoid float precision loss, and JSON numbers are floats. In Codec::JSON this also keeps Decimal fields from silently noop-passing via the Numeric noop (a BigDecimal is not JSON-native).

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object



657
# File 'lib/plumb/codec.rb', line 657

def decode(str) = BigDecimal(str)

#encode(dec) ⇒ Object



656
# File 'lib/plumb/codec.rb', line 656

def encode(dec) = dec.to_s('F')