Skip to content

Commit

Permalink
Adjust decimal value preparation for old String.slice behavior, in …
Browse files Browse the repository at this point in the history
…elixir versions 1.11.4 and 1.12.3
  • Loading branch information
ShPakvel committed Nov 28, 2024
1 parent ed6ef80 commit 61395fb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mix/phoenix/attribute.ex
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ defmodule Mix.Phoenix.Attribute do
scale = Map.get(options, :scale, scale_default)
fractional_part = fractional_part |> String.slice(0, scale) |> String.pad_trailing(scale, "0")

whole_length = precision - scale
# NOTE: `min` applied to adjust for old `String.slice` behavior, in elixir versions 1.11.4 and 1.12.3
whole_length = [String.length(whole_part), precision - scale] |> Enum.min()
whole_part = whole_part |> String.slice(-whole_length, whole_length)

"#{whole_part}.#{fractional_part}"
Expand Down

0 comments on commit 61395fb

Please sign in to comment.