awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.08k stars 454 forks source link

Patching awesome_bigdecimal to not have lossy precision. #91

Closed evansenter closed 12 years ago

evansenter commented 12 years ago

The formatting of BigDecimal and Rational numbers by calling to_f messes up the precision of the numbers displayed, thus misleading the user as to the value of the number being shown. In example:

1.9.3p194 :001 > require "bigdecimal"
 => true 
1.9.3p194 :002 > ap BigDecimal.new("1234567890" * 10)
1.2345678901234567e+99
 => #<BigDecimal:7f8d7b858558,'0.1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 123456789E100',108(117)>

This patch addresses that issue by pre-formatting BigDecimal and Rationals with to_s before calling colorize to ensure that all precision is preserved in the output.