Class CoordinateFormatter


  • public final class CoordinateFormatter
    extends Object
    Formats coordinates with a given number of decimals, using code more efficient than NumberFormat when possible. The class is not thread safe, create a new instance for each thread using it.
    • Constructor Summary

      Constructors 
      Constructor Description
      CoordinateFormatter​(int numDecimals)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String format​(double x)
      Formats a number with the configured number of decimals.
      StringBuffer format​(double x, StringBuffer sb)
      Formats a number with the configured number of decimals
      int getMaximumFractionDigits()
      Returns the maximum number of digits allowed in the fraction portion of a number.
      boolean isForcedDecimal()
      Returns the force decimal flag, see setForcedDecimal(boolean)
      boolean isPadWithZeros()  
      void setForcedDecimal​(boolean forcedDecimal)
      When set to true, forces decimal representation of numbers, otherwise allows scientific notation too (for very large of very small numbers).
      void setMaximumFractionDigits​(int maxDigits)  
      void setPadWithZeros​(boolean pad)  
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CoordinateFormatter

        public CoordinateFormatter​(int numDecimals)
    • Method Detail

      • format

        public String format​(double x)
        Formats a number with the configured number of decimals. For better performance best use format(double, StringBuffer) against a re-used StringBuffer
      • format

        public StringBuffer format​(double x,
                                   StringBuffer sb)
        Formats a number with the configured number of decimals
      • getMaximumFractionDigits

        public int getMaximumFractionDigits()
        Returns the maximum number of digits allowed in the fraction portion of a number.
        Returns:
        the maximum number of digits.
      • setMaximumFractionDigits

        public void setMaximumFractionDigits​(int maxDigits)
      • isPadWithZeros

        public boolean isPadWithZeros()
      • setForcedDecimal

        public void setForcedDecimal​(boolean forcedDecimal)
        When set to true, forces decimal representation of numbers, otherwise allows scientific notation too (for very large of very small numbers). False by default.
      • setPadWithZeros

        public void setPadWithZeros​(boolean pad)