From aba8a8eb3c958be731a4e1286f0178bbce4b2510 Mon Sep 17 00:00:00 2001 From: Justin McBride Date: Tue, 1 Sep 2026 01:04:27 -0600 Subject: [PATCH] Show exact share count in the holding drawer (#3305) * Show exact share count in the holding drawer Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014YrdY9jvCUtG3GhgZ5Skx1 * Test that the holding drawer does not round the share count Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014YrdY9jvCUtG3GhgZ5Skx1 --------- Co-authored-by: Claude --- app/helpers/application_helper.rb | 12 +++++++----- app/views/holdings/show.html.erb | 4 ++-- test/controllers/holdings_controller_test.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8d92c031..eff64a7af 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -226,19 +226,21 @@ module ApplicationHelper ENV.fetch("DEV_WEBHOOKS_URL", root_url).chomp("/") + "/enable_banking_items/callback" end - # Formats quantity with adaptive precision based on the value size. + # Formats a holding quantity with adaptive precision based on the value size. # Shows more decimal places for small quantities (common with crypto). # # @param qty [Numeric] The quantity to format - # @param max_precision [Integer] Maximum precision for very small numbers + # @param exact [Boolean] Show the full stored precision, without rounding # @return [String] Formatted quantity with appropriate precision - def format_quantity(qty) + def format_quantity(qty, exact: false) return "0" if qty.nil? || qty.zero? abs_qty = qty.abs - precision = if abs_qty >= 1 - 1 # "10.5" + precision = if exact + 8 # "10.374" + elsif abs_qty >= 1 + 1 # "10.4" elsif abs_qty >= 0.01 2 # "0.52" elsif abs_qty >= 0.0001 diff --git a/app/views/holdings/show.html.erb b/app/views/holdings/show.html.erb index e382fda31..14d7cfd5c 100644 --- a/app/views/holdings/show.html.erb +++ b/app/views/holdings/show.html.erb @@ -96,7 +96,7 @@
<%= t(".shares_label") %>
-
<%= format_quantity(@holding.qty) %>
+
<%= format_quantity(@holding.qty, exact: true) %>
<%= t(".portfolio_weight_label") %>
@@ -141,7 +141,7 @@ class: "space-y-3", data: drawer_form_data do |f| %>

- <%= t("holdings.cost_basis_cell.set_cost_basis_header", ticker: @holding.ticker, qty: format_quantity(@holding.qty)) %> + <%= t("holdings.cost_basis_cell.set_cost_basis_header", ticker: @holding.ticker, qty: format_quantity(@holding.qty, exact: true)) %>

diff --git a/test/controllers/holdings_controller_test.rb b/test/controllers/holdings_controller_test.rb index dfa52d499..6e88a2a19 100644 --- a/test/controllers/holdings_controller_test.rb +++ b/test/controllers/holdings_controller_test.rb @@ -18,6 +18,14 @@ class HoldingsControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "shows exact share count without rounding" do + @holding.update!(qty: 10.374) + + get holding_path(@holding) + + assert_select "##{dom_id(@holding, :shares)}", text: "10.374" + end + test "destroys holding and associated entries" do assert_difference -> { Holding.count } => -1, -> { Entry.count } => -1 do