From 9728f171c35fc16d430aac9fee94842a89a5c9f1 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 11 Mar 2022 20:09:42 +0100 Subject: [PATCH] Ignore prefixes for percentage --- internal/ccUnits/ccUnits.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/ccUnits/ccUnits.go b/internal/ccUnits/ccUnits.go index 656fa81..b339ef3 100644 --- a/internal/ccUnits/ccUnits.go +++ b/internal/ccUnits/ccUnits.go @@ -59,14 +59,8 @@ func (u *unit) getDivMeasure() Measure { func GetPrefixFactor(in Prefix, out Prefix) func(value float64) float64 { var factor = 1.0 - var in_prefix = 1.0 - var out_prefix = 1.0 - if in != Base { - in_prefix = float64(in) - } - if out != Base { - out_prefix = float64(out) - } + var in_prefix = float64(in) + var out_prefix = float64(out) factor = in_prefix / out_prefix return func(value float64) float64 { return factor } } @@ -110,12 +104,16 @@ func NewUnit(unitStr string) Unit { if len(measures) > 1 { div = NewMeasure(measures[1]) } - // Special case for 'm' as prefix for Bytes as thers is nothing like MilliBytes + switch m { + // Special case for 'm' as prefix for Bytes and some others as thers is no unit like MilliBytes case Bytes, Flops, Packets, Events, Cycles, Requests: if pre == Milli { pre = Mega } + // Special case for percentage. No/ignore prefix + case Percentage: + pre = Base } u.prefix = pre u.measure = m