Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:15:16+00:00 2026-05-26T04:15:16+00:00

Possible Duplicate: Rails 3. How do display two decimal places in edit form? I

  • 0

Possible Duplicate:
Rails 3. How do display two decimal places in edit form?

I know I can use sprintf to limit to two decimal places.

When I redisplay the prices in a form or just in a table, sometimes I get 80, instead of 80.00. Wouldn’t be better to just store the price with the two decimal places from the very moment the price is entered in the database? That way, whenever it’s displayed, it will ALWAYS show the two decimal places. If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:15:17+00:00Added an answer on May 26, 2026 at 4:15 am

    You should try using the :decimal type of database field, with the :scale set to 2

    To add a decimal column to a new table;

    create_table :my_table do |t|
      t.decimal :my_column, :scale => 2
    end
    

    To add a column to an existing table;

    add_column :my_table, :my_column, :decimal, :scale => 2
    

    It is wise to have precisions since some database does not have precision defaults. Such as postgresql:

     add_column :my_table, my_column, precision: 30, scale: 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between -%> and %> in rails I need to know what
Possible Duplicate: Rails - Help understanding how to use :dependent => :destroy I have
Possible Duplicate: Access a view helper for a model in rails I know this
Possible Duplicate: Can you share a file and it's history between two git repositories?
Possible Duplicate: Ruby on Rails keybard shortcuts Hi all - does anyone know how
Possible Duplicate: Ruby on Rails: How can i join with a derived table? posts
Possible Duplicate: Best way to use html5 data attributes with rails content_tag helper? How
Possible Duplicate: Can't convert String into integer in ruby/ruby-on-rails I'm running through a tutorial
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Rails 2.3-style plugins and deprecation warnings running task in Heroku A few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.