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 8627431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:16:43+00:00 2026-06-12T08:16:43+00:00

I have an Invoice to which Items can be added using some jQuery magic.

  • 0

I have an Invoice to which Items can be added using some jQuery magic.

Controller:

def new    
  @invoice = Invoice.new
  @invoice.with_blank_items(current_user) 
  @title = "New invoice"
end

Model:

def with_blank_items(user, n = 1)
  n.times do
    items.build(:price => user.preference.hourly_rate)
  end
  self
end

View:

<%= f.text_field number_with_precision(:price, :strip_insignificant_zeros => true) %>

Now the problem is that the price of a newly added item is always displayed in the format XX.X, i.e. with one decimal place, no matter if it is zero or not.

I don’t like that and I want a price of 50 to be displayed as 50 and not as 50.0.

Once the invoice gets saved to the database, unnecessary zeros get dropped and that’s perfect.

How can I strip insignificant zeros on newly added items as well?

  • 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-06-12T08:16:44+00:00Added an answer on June 12, 2026 at 8:16 am

    You can try to format the values the right way before assigning:

    items.build(:price => '%g' % user.preference.hourly_rate)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an app in CodeIgniter. I have an invoice form which uses jQuery
I want to create an invoice in rails. Invoice can have items and each
I have written some code which extracts and invoice from various hashes, arrays, arrays
I have some code like: <table class=invisibleforprint> <thead> <tr class=mainheader> <th>@Html.ActionLink(Invoice Number, Index, new
Assume we have an Invoice entity which has many InvoiceDetails . Each invoice detail
I have a listview with lists lines of an invoice (Which are editable), each
I have a query which produces a list of orders like this: Invoice Description
If I have an Invoice Line Items table and a Products table, and I
I am using this fantastic example of a jQuery editable invoice as a template
The invoice input values which hold the totals of invoice line items that get

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.