Search code examples
ruby-on-railsrubyfloating-pointscientific-notation

Easy to read scientific notation on Rails console


I have a Postgresql table column which's type is numeric(20,4). When I play with the data through rails console, ActiveRecord display the values in scientific notation.

All I can think of adding attribute :column_name, :float to the related modal, but not sure if there will be any side effects because of it.

So the question is; does anyone one if there is anything I can do to make it easier for reading the data on rails console and do not have any side effects on the app itself?


Solution

  • You can monkeypatch specifically BigDecimal class specifically for console

    development.rb

      console do
        class BigDecimal
          def inspect
            to_f
          end
        end
      end