lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.13 vs lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.16
- old
+ new
@@ -102,10 +102,17 @@
worksheet.instance_variable_set("@formula_cache",formula_cache)
@worksheets[worksheet_name] = worksheet
worksheet
end
+ def text(number,format)
+ return number if iserr(number)
+ return format if iserr(format)
+ raise Exception.new("format #{format} not implemented") unless format.is_a?(Numeric)
+ number.round(format).to_s
+ end
+
def round(number,decimal_places)
return number if iserr(number)
return decimal_places if iserr(decimal_places)
return :na unless number.is_a?(Numeric)
return :na unless decimal_places.is_a?(Numeric)
@@ -135,9 +142,10 @@
return :na unless divisor.is_a?(Numeric)
number % divisor
end
def pmt(rate,periods,principal)
+ return -(principal / periods) if rate == 0
-principal*(rate*((1+rate)**periods))/(((1+rate)**periods)-1)
end
def npv(rate,*cashflows)
discount_factor = 1
\ No newline at end of file