Modified trimZeros to modify the passed value.
This commit is contained in:
parent
1b2c599854
commit
29c8c83972
1 changed files with 14 additions and 15 deletions
|
|
@ -1456,21 +1456,20 @@ proc formatFloat*(f: float, format: FloatFormatMode = ffDefault,
|
||||||
## after the decimal point for Nim's ``float`` type.
|
## after the decimal point for Nim's ``float`` type.
|
||||||
result = formatBiggestFloat(f, format, precision, decimalSep)
|
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
|
## Trim trailing zeros from a formatted floating point
|
||||||
## value (`x`).
|
## value (`x`). Modifies the passed value.
|
||||||
var splResult: seq[string]
|
var spl: seq[string]
|
||||||
result = x
|
if x.contains('.') or x.contains(','):
|
||||||
if result.contains('.') or result.contains(','):
|
if x.contains('e'):
|
||||||
if result.contains('e'):
|
spl= x.split('e')
|
||||||
splResult = result.split('e')
|
x = spl[0]
|
||||||
result = splResult[0]
|
while x[x.high] == '0':
|
||||||
while result[result.high] == '0':
|
x.setLen(x.len-1)
|
||||||
result.setLen(result.len-1)
|
if x[x.high] in [',', '.']:
|
||||||
if result[result.high] in [',', '.']:
|
x.setLen(x.len-1)
|
||||||
result.setLen(result.len-1)
|
if spl.len > 0:
|
||||||
if splResult.len > 0:
|
x &= "e" & spl[1]
|
||||||
result &= "e" & splResult[1]
|
|
||||||
|
|
||||||
type
|
type
|
||||||
BinaryPrefixMode* = enum ## the different names for binary prefixes
|
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
|
# xb has the integer number for the latest value; index should be correct
|
||||||
fbytes = bytes.float / (1'i64 shl (matchedIndex*10)).float
|
fbytes = bytes.float / (1'i64 shl (matchedIndex*10)).float
|
||||||
result = formatFloat(fbytes, format=ffDecimal, precision=3, decimalSep=decimalSep)
|
result = formatFloat(fbytes, format=ffDecimal, precision=3, decimalSep=decimalSep)
|
||||||
result = trimZeros(result)
|
result.trimZeros()
|
||||||
if includeSpace:
|
if includeSpace:
|
||||||
result &= " "
|
result &= " "
|
||||||
result &= prefixes[matchedIndex]
|
result &= prefixes[matchedIndex]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue