Class: Float

Inherits:
Object show all
Defined in:
lib/cbor-diagnostic.rb

Instance Method Summary collapse

Instance Method Details

#cbor_diagnostic(_ = nil) ⇒ Object

do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1)



20
21
22
23
24
25
26
27
# File 'lib/cbor-diagnostic.rb', line 20

def cbor_diagnostic(_=nil)           # do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1)
  a = abs
  if a < 1 && a >= 1e-6
    inspect.sub(/(\d)[.](\d+)e-(\d+)/) {"0.#{"0" * ($3.to_i - 1)}#{$1}#{$2}"}
  else
    inspect.sub(/(e[+-])0+/) {$1}
  end
end