Skip to content

Commit 22e979a

Browse files
authored
Use floating-point format for BigDecimal stringification (#2022)
## Summary - BigDecimal values now stringify using `to_s("F")` format instead of the default `to_s` ## Why Ruby's default `BigDecimal#to_s` produces engineering/scientific notation for certain values: ```ruby BigDecimal("0.00001").to_s # => "0.1E-4" BigDecimal("12345678.9").to_s # => "0.123456789E8" ``` This is rarely the desired output in templates. Using `to_s("F")` produces the expected floating-point format: ```ruby BigDecimal("0.00001").to_s("F") # => "0.00001" BigDecimal("12345678.9").to_s("F") # => "12345678.9" ```
1 parent 735d551 commit 22e979a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/liquid/utils.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def self.to_liquid_value(obj)
9595

9696
def self.to_s(obj, seen = {})
9797
case obj
98+
when BigDecimal
99+
obj.to_s("F")
98100
when Hash
99101
# If the custom hash implementation overrides `#to_s`, use their
100102
# custom implementation. Otherwise we use Liquid's default

0 commit comments

Comments
 (0)