Class NumberFormatter

java.lang.Object
com.saperion.common.lang.format.NumberFormatter

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

    • formatWithThousandsSeparator

      public static 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