Easy way to prevent rails console displaying numbers (decimal, float, integers) in scientific notation?

262 views Asked by At

Is there some default configuration that can be altered to prevent scientific notation in the rails console without having to configure it on a per-column basis? (i.e. I'd like to just run some config line once somewhere and have it apply across all tables/columns for that app, if possible).

Example

Here is an example where scientific notation sort of gets in the way

Product.first

cost: 0.99999998999923e12,
currency: "USD",
charge: 0.55e1,
charge_currency: "AUD",
price: 0.5e2,
price_currency: "AUD"

I'd prefer to see 999999989999.23 instead of 0.99999998999923e12, 5.5 instead of 0.55e1, 50 instead of 0.5e2. I find regular numbers much more natural and easy to read.

What I know so far

There are a couple of ideas in the answers to Rails console shows value in scientific notation, but both are on a per column/attribute basis.

Note

I'd be happy to install a gem (I already use pry if that helps), and basically want a convenient way of avoiding scientific notation when displaying integers/floats/decimals but without having to write code specific to the model/columns/types.

0

There are 0 answers