summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gerber/tests/test_utils.py3
-rw-r--r--gerber/utils.py5
2 files changed, 8 insertions, 0 deletions
diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py
index 1c3f1e5..fe9b2e6 100644
--- a/gerber/tests/test_utils.py
+++ b/gerber/tests/test_utils.py
@@ -37,6 +37,9 @@ def test_zero_suppression():
assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
+ assert_equal(write_gerber_value(0.000000001, fmt, 'leading'), '0')
+ assert_equal(write_gerber_value(0.000000001, fmt, 'trailing'), '0')
+
def test_format():
""" Test gerber value parser and writer handle format correctly
diff --git a/gerber/utils.py b/gerber/utils.py
index 86119ba..23575b3 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -138,6 +138,11 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
fmtstring = '%%0%d.0%df' % (MAX_DIGITS + 1, decimal_digits)
digits = [val for val in fmtstring % value if val != '.']
+ # If all the digits are 0, return '0'.
+ digit_sum = reduce(lambda x,y:x+int(y), digits, 0)
+ if digit_sum == 0:
+ return '0'
+
# Suppression...
if zero_suppression == 'trailing':
while digits and digits[-1] == '0':