Show exact share count in the holding drawer (#3305)

* Show exact share count in the holding drawer

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014YrdY9jvCUtG3GhgZ5Skx1

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Justin McBride
2026-09-01 09:04:27 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 61c1e0d7e1
commit aba8a8eb3c
3 changed files with 17 additions and 7 deletions
+7 -5
View File
@@ -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
+2 -2
View File
@@ -96,7 +96,7 @@
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-secondary"><%= t(".shares_label") %></dt>
<dd class="text-primary"><%= format_quantity(@holding.qty) %></dd>
<dd id="<%= dom_id(@holding, :shares) %>" class="text-primary"><%= format_quantity(@holding.qty, exact: true) %></dd>
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-secondary"><%= t(".portfolio_weight_label") %></dt>
@@ -141,7 +141,7 @@
class: "space-y-3",
data: drawer_form_data do |f| %>
<p class="text-xs text-secondary mb-2">
<%= 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)) %>
</p>
<!-- Total cost basis input -->
<div class="form-field">
@@ -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