Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
waxx/patch.rb

Instance Method Summary collapse

Instance Method Details

#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object

Format a number

size: number of decimal places
zero_as: will display zero as "" (blank), "-" (dash), etc.
t: thousands seperator
d: decimal seperator


88
89
90
91
92
93
94
# File 'waxx/patch.rb', line 88

def f(size=2, zero_as="", t=",", d=".")
  return zero_as if zero?
  num_parts = to_s.split(".")
  x = num_parts[0].gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{t}")
  return x if size == 0
  x << (d + (num_parts[1].to_s + "0000000")[0,size])
end

#hObject

HTML format (self – no escaping needed)



80
81
82
# File 'waxx/patch.rb', line 80

def h
  self
end