Class: Float

Inherits:
Object show all
Defined in:
lib/shorthand.rb

Instance Method Summary collapse

Instance Method Details

#numeric?Boolean

Returns:

  • (Boolean)


253
# File 'lib/shorthand.rb', line 253

def numeric?() true end

#s(p = 2, ch = '0') ⇒ Object



254
255
256
257
258
259
260
# File 'lib/shorthand.rb', line 254

def s(p=2,ch='0')
  return ch if self == 0.0 && p == 0 && !ch.nil?
  v = self.round
  v = (self > 0.0 ? self.ceil : self.floor) if v == 0 && !ch.nil?
  ret = p > 0 ? ("%.#{p}f" % self) : v.to_s
  (ret =~ /^0+(\.0+)?$/ && !ch.nil?) ? ch : ret
end