diff --git a/pandas/core/style.py b/pandas/core/style.py index a5a42c2bb47a7..bced50926e275 100644 --- a/pandas/core/style.py +++ b/pandas/core/style.py @@ -118,7 +118,11 @@ class Styler(object): {% for c in r %} <{{c.type}} id="T_{{uuid}}{{c.id}}" class="{{c.class}}"> {% if c.value is number %} - {{c.value|round(precision)}} + {% if precision %} + {{c.value|round(precision)}} + {% else %} + {{'%.0f'|format(c.value)}} + {% endif %} {% else %} {{c.value}} {% endif %} diff --git a/pandas/tests/test_style.py b/pandas/tests/test_style.py index b9ca3f331711d..188696397e24b 100644 --- a/pandas/tests/test_style.py +++ b/pandas/tests/test_style.py @@ -379,6 +379,12 @@ def test_precision(self): self.assertTrue(s is s2) self.assertEqual(s.precision, 4) + def test_precision_zero(self): + df = pd.DataFrame({'A': 100, 'B': [0, 1, 2, 3, np.nan]}) + df['C'] = df['A'] / df['B'] + result = df.style.set_precision(0).render() + self.assertEqual(result.count('.'), 0) + def test_apply_none(self): def f(x): return pd.DataFrame(np.where(x == x.max(), 'color: red', ''),