lib/dentaku/ast/functions/rounddown.rb in dentaku-2.0.5 vs lib/dentaku/ast/functions/rounddown.rb in dentaku-2.0.6
- old
+ new
@@ -1,5 +1,7 @@
require_relative '../function'
-Dentaku::AST::Function.register(:rounddown, :numeric, ->(numeric) {
- numeric.floor
+Dentaku::AST::Function.register(:rounddown, :numeric, ->(numeric, precision=0) {
+ tens = 10.0**precision
+ result = (numeric * tens).floor / tens
+ precision <= 0 ? result.to_i : result
})