Skip to content

Commit

Permalink
Avoid floats and type conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Feb 29, 2024
1 parent 4a5fae9 commit 9a0e780
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions go/textutil/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func TruncateText(text string, limit int, location TruncationLocation, indicator
}
switch location {
case TruncationLocationMiddle:
prefix := int((float64(limit) * 0.5) - float64(len(indicator)))
suffix := int(ol - int(prefix+len(indicator)) + 1)
prefix := (limit / 2) - len(indicator)
suffix := (ol - (prefix + len(indicator))) + 1
return fmt.Sprintf("%s%s%s", text[:prefix], indicator, text[suffix:]), nil
case TruncationLocationEnd:
return text[:limit-(len(indicator)+1)] + indicator, nil
Expand Down

0 comments on commit 9a0e780

Please sign in to comment.