2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-21 17:11:58 +00:00

Modify float formatting again

Make sure at least one decimal is in a float.

Maximum precision of 5 past.
This commit is contained in:
Jarrod Johnson 2023-02-24 12:03:43 -05:00
parent 5ea214a726
commit 59b07665ab

View File

@ -37,6 +37,12 @@ class hybridcsv(csv.excel):
lineterminator = '\n'
def floatformat(num):
fm = u'{:.5f}'.format(num).rstrip('0')
if fm[-1:] == u'.':
return fm + u'0'
return fm
csv.register_dialect('hybrid', hybridcsv)
import confluent.client as client
@ -135,7 +141,7 @@ def sensorpass(showout=True, appendtime=False):
if sensedata['value'] is None:
showval = ''
elif isinstance(sensedata['value'], float):
showval = u' {0:.5g} '.format(sensedata['value'])
showval = floatformat(sensedata['value'])
else:
showval = u' {0} '.format(sensedata['value'])
if sensedata['units'] not in (None, u''):
@ -192,7 +198,7 @@ def format_csv(csvwriter, orderedsensors, resdata, showtime=True):
else:
datum = healthstates
if isinstance(datum, float):
datum = '{:.5g}'.format(datum)
datum = floatformat(datum)
rowdata.append(datum)
except KeyError:
rowdata.append('N/A')