summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-10-23 17:59:21 +0200
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-10-23 17:59:21 +0200
commit8f51ef3a567ecb981e480be0f8ca65f8c8242889 (patch)
tree4cdb5b52a52ca13366b9a21c6951022842cb5c9b
parentCanvas: Add MeasureAndModifyTextPixels (diff)
downloadwireguard-windows-8f51ef3a567ecb981e480be0f8ca65f8c8242889.tar.xz
wireguard-windows-8f51ef3a567ecb981e480be0f8ca65f8c8242889.zip
Fix FormatFloatGrouped
-rw-r--r--util.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/util.go b/util.go
index 8fba2446..54360a68 100644
--- a/util.go
+++ b/util.go
@@ -172,7 +172,7 @@ func FormatFloat(f float64, prec int) string {
}
func FormatFloatGrouped(f float64, prec int) string {
- return formatFloatString(strconv.FormatFloat(f, 'f', prec, 64), prec, true)
+ return formatFloatString(strconv.FormatFloat(f, 'f', maxi(1, prec), 64), prec, true)
}
func formatBigRat(r *big.Rat, prec int) string {
@@ -203,7 +203,7 @@ func formatFloatString(s string, prec int, grouped bool) string {
s = s[1:]
}
- intLen := len(s) - prec - 1
+ intLen := len(s) - maxi(1, prec) - 1
n := intLen % 3
if n != 0 {
@@ -218,7 +218,13 @@ func formatFloatString(s string, prec int, grouped bool) string {
b.WriteString(s[intLen:])
- return b.String()
+ s = b.String()
+
+ if prec == 0 {
+ s = s[:len(s)-2]
+ }
+
+ return s
}
func applyEnabledToDescendants(window Window, enabled bool) {