diff options
author | A. S. Budden <abudden@gmail.com> | 2016-06-01 20:15:55 +0100 |
---|---|---|
committer | A. S. Budden <abudden@gmail.com> | 2016-06-01 20:15:55 +0100 |
commit | 29c8c839728f216447c49aa26158b004055d4f1d (patch) | |
tree | a58ea5261362d13274c1dc8a0ca6eefad72d39df /lib | |
parent | 1b2c5998540bf5f522619cc532fd416c93b51174 (diff) | |
download | Nim-29c8c839728f216447c49aa26158b004055d4f1d.tar.gz |
Modified trimZeros to modify the passed value.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/strutils.nim | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 4f9d29c8c..88f74b893 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1456,21 +1456,20 @@ proc formatFloat*(f: float, format: FloatFormatMode = ffDefault, ## after the decimal point for Nim's ``float`` type. result = formatBiggestFloat(f, format, precision, decimalSep) -proc trimZeros*(x: string): string {.noSideEffect.} = +proc trimZeros*(x: var string) {.noSideEffect.} = ## Trim trailing zeros from a formatted floating point - ## value (`x`). - var splResult: seq[string] - result = x - if result.contains('.') or result.contains(','): - if result.contains('e'): - splResult = result.split('e') - result = splResult[0] - while result[result.high] == '0': - result.setLen(result.len-1) - if result[result.high] in [',', '.']: - result.setLen(result.len-1) - if splResult.len > 0: - result &= "e" & splResult[1] + ## value (`x`). Modifies the passed value. + var spl: seq[string] + if x.contains('.') or x.contains(','): + if x.contains('e'): + spl= x.split('e') + x = spl[0] + while x[x.high] == '0': + x.setLen(x.len-1) + if x[x.high] in [',', '.']: + x.setLen(x.len-1) + if spl.len > 0: + x &= "e" & spl[1] type BinaryPrefixMode* = enum ## the different names for binary prefixes @@ -1527,7 +1526,7 @@ proc formatSize*(bytes: int64, # xb has the integer number for the latest value; index should be correct fbytes = bytes.float / (1'i64 shl (matchedIndex*10)).float result = formatFloat(fbytes, format=ffDecimal, precision=3, decimalSep=decimalSep) - result = trimZeros(result) + result.trimZeros() if includeSpace: result &= " " result &= prefixes[matchedIndex] |