Class NumberFormatter


  • public final class NumberFormatter
    extends java.lang.Object
    Contains utility methods for Number formatting.
    Author:
    agz
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatWithThousandsSeparator​(long value, char thousandsSeparator)
      Converts the specified long value to a string using the specified thousands separator.
      • Methods inherited from class java.lang.Object

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

      • formatWithThousandsSeparator

        public static java.lang.String formatWithThousandsSeparator​(long value,
                                                                    char thousandsSeparator)
        Converts the specified long value to a string using the specified thousands separator.

        Usually one can use NumberFormat for this purpose, but this class is overloaded with different aspects to parse and format a lot of different things, making it inefficient and resource intensive.

        This method is optimized for this single use case to save time and resources.

        It is approximately 5 times faster than NumberFormat.format(long) on a prepared NumberFormat -instance and approximately 10 times faster than creating a NumberFormat-instance and formatting then (like NumberFormat.getInstance().format()).

        Parameters:
        value - value to format
        thousandsSeparator - thousands separator to use
        Returns:
        formatted string for the specified long value