Skip to content

Commit 8a8c667

Browse files
mjcclaude
andcommitted
Update deps; fix file_size scientific notation bug
Float.round/2 can return 1000.0 at unit boundaries, which Elixir's string interpolation renders as "1.0e3" (scientific notation). Switch to :erlang.float_to_binary/2 with decimals: 1 to always produce decimal output. Also updates mix.lock for latest dep versions including exqlite fork. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fcc7bea commit 8a8c667

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

lib/reencodarr/formatters.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ defmodule Reencodarr.Formatters do
1010
@spec file_size(non_neg_integer()) :: String.t()
1111
def file_size(bytes) when is_integer(bytes) and bytes >= 0 do
1212
cond do
13-
bytes >= 1_099_511_627_776 -> "#{Float.round(bytes / 1_099_511_627_776, 1)} TiB"
14-
bytes >= 1_073_741_824 -> "#{Float.round(bytes / 1_073_741_824, 1)} GiB"
15-
bytes >= 1_048_576 -> "#{Float.round(bytes / 1_048_576, 1)} MiB"
16-
bytes >= 1024 -> "#{Float.round(bytes / 1024, 1)} KiB"
13+
bytes >= 1_099_511_627_776 -> "#{fmt(bytes / 1_099_511_627_776)} TiB"
14+
bytes >= 1_073_741_824 -> "#{fmt(bytes / 1_073_741_824)} GiB"
15+
bytes >= 1_048_576 -> "#{fmt(bytes / 1_048_576)} MiB"
16+
bytes >= 1024 -> "#{fmt(bytes / 1024)} KiB"
1717
true -> "#{bytes} B"
1818
end
1919
end
2020

2121
@spec file_size(any()) :: String.t()
2222
def file_size(_), do: "N/A"
2323

24+
defp fmt(value), do: :erlang.float_to_binary(value, decimals: 1)
25+
2426
@spec file_size_gib(pos_integer()) :: float()
2527
def file_size_gib(bytes) when is_integer(bytes) and bytes > 0 do
2628
Float.round(bytes / 1_073_741_824, 2)

0 commit comments

Comments
 (0)