lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.4 vs lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.5

- old
+ new

@@ -100,11 +100,19 @@ worksheet.instance_variable_set("@worksheets",@worksheets) worksheet.instance_variable_set("@formula_cache",formula_cache) @worksheets[worksheet_name] = worksheet worksheet 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) + number.round(decimal_places) + end + def sum(*args) flatten_and_inject(args) do |counter,arg| arg.is_a?(Numeric) ? counter + arg.to_f : counter end end @@ -309,10 +317,12 @@ def ref(*arg) :ref end def iserr(arg) - arg.is_a? Symbol + return true if arg.is_a? Symbol + return true if arg.is_a?(Float) && arg.nan? + false end def excel_if(condition,true_value,false_value) condition ? true_value : false_value end \ No newline at end of file