Class: Latex::Formatters::DecimalFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-latex.rb

Instance Method Summary collapse

Constructor Details

#initialize(decimals = 2, comma = true, nums = nil) ⇒ DecimalFormatter

Returns a new instance of DecimalFormatter.



388
389
390
391
# File 'lib/ruby-latex.rb', line 388

def initialize(decimals=2, comma=true, nums=nil)
    @format = "%#{nums}.#{decimals}f"
    @comma = comma
end

Instance Method Details

#call(object) ⇒ Object



393
394
395
396
397
# File 'lib/ruby-latex.rb', line 393

def call(object)
    result = @format % [object.to_f]
    result = result.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") if @comma
    return result
end