ruby-on-railsrails-console

Rails console shows value in scientific notation


I have model named Dish which has an attribute cost of float type. I've set precision to 15 and scale to 2. The problem is in rails console, the value for cost is displayed in scientific notation.

cost: 0.102e2

How to display in decimals?


Solution

  • you can use to_f for simple format, but for more options you can also use NumberHelper module, you can format with many format from this helper module , here is reference

    from your console:

    include ActionView::Helpers::NumberHelper
    number_with_precision(cost, precision: 2)