From 18cf1ca1c742031ed64fa66b11cfe4f406af4e7a Mon Sep 17 00:00:00 2001
From: Tim Molter <tim.molter@gmail.com>
Date: Sun, 12 Apr 2015 16:48:17 +0200
Subject: [PATCH] add formatting check to always print the value zero as "0"

---
 .../internal/chartpart/AxisTickNumericalCalculator.java      | 2 +-
 .../com/xeiam/xchart/internal/chartpart/NumberFormatter.java | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java
index 5ef23fb8..ba41617d 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java
@@ -74,7 +74,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
     // generate all tickLabels and tickLocations from the first to last position
     for (BigDecimal value = cleanedFirstPosition; value.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; value = value.add(cleanedGridStep)) {
 
-      // System.out.println(tickPosition);
+      // System.out.println(value);
       String tickLabel = numberFormatter.formatNumber(value, minValue, maxValue, axisDirection);
       // System.out.println(tickLabel);
       tickLabels.add(tickLabel);
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java
index 41782c26..6e8682f9 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java
@@ -43,6 +43,11 @@ public class NumberFormatter {
     // System.out.println("min: " + min);
     // System.out.println("max: " + max);
 
+    // some special cases first
+    if (value.compareTo(BigDecimal.ZERO) == 0) {
+      return "0";
+    }
+
     double difference = max - min;
     int placeOfDifference;
     if (difference == 0.0) {
-- 
GitLab