mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
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"
```
This commit is contained in:
@@ -95,6 +95,8 @@ module Liquid
|
|||||||
|
|
||||||
def self.to_s(obj, seen = {})
|
def self.to_s(obj, seen = {})
|
||||||
case obj
|
case obj
|
||||||
|
when BigDecimal
|
||||||
|
obj.to_s("F")
|
||||||
when Hash
|
when Hash
|
||||||
# If the custom hash implementation overrides `#to_s`, use their
|
# If the custom hash implementation overrides `#to_s`, use their
|
||||||
# custom implementation. Otherwise we use Liquid's default
|
# custom implementation. Otherwise we use Liquid's default
|
||||||
|
|||||||
Reference in New Issue
Block a user