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("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)) %>