Summing floats with the `sum` filter
jg-rp opened this issue · comments
James commented
When using the sum
filter on an array containing floats, we get a BigDecimal
result, which is rendered in scientific notation.
require 'liquid'
template = Liquid::Template.parse("Result: {{ a | sum }}")
puts template.render!({"a" => [0.1, 0.2, 0.3]})
Output
Result: 0.6e0
Expected output
Result: 0.6
For consistency with existing math filters, would it be possible to convert a BigDecimal
result to a float, just like the round
filter does?
liquid/lib/liquid/standardfilters.rb
Line 791 in 77293d4
Many thanks.