Class RMNumberFormat

All Implemented Interfaces:
RMArchiver.Archiving, RMFormat, Serializable, Cloneable

public class RMNumberFormat extends DecimalFormat implements RMFormat, RMArchiver.Archiving
This subclass extends DecimalFormat to implement ReportMill's RMFormat interface and to support the extended features "Negative in Red" and "Null String". It also has a toPattern like method, getFormatString, for the purposes of archival.

Those getFormatString/setFormatString support arbitrary decimal and grouping separators. This may be dangerous since when people use the default English versions of those, I think they change depending on the default JVM Locale. Only dangerous if someone wants to generate English Separators from a foreign local, I guess.

Also, our modified pattern format can be ambiguous if either decimal or grouping separator not included. In this case we assume any separator preceded by a '0' is the decimal separator. This seems reasonable since a decimal separator preceded by # could result in an empty string or a fractional number with no leading zero (like ".123" instead of "0.123") which seems somewhat rare. And also a grouping separator preceeded by 0 seems somewhat rare because it could result in a long zero string like "0,000".

I suppose we should instead have a syntax explicitly declaring decimal and group separators: "$ #,##0.00;ds=,;gs=.".

See Also:
  • Field Details

  • Constructor Details

    • RMNumberFormat

      public RMNumberFormat()
      Creates an uninitialized number format.
    • RMNumberFormat

      public RMNumberFormat(String aFormatString)
      Creates a number format for the given format string.
    • RMNumberFormat

      public RMNumberFormat(RMNumberFormat aFormat)
      Creates a number format identical to the given format.
  • Method Details

    • getNullString

      public String getNullString()
      Returns the String that is substituted when this format is asked to provide stringForObjectValue(null).
    • setNullString

      public void setNullString(String aString)
      Sets the String that is substituted when this format is asked to provide stringForObjectValue(null).
    • isNegativeInRed

      public boolean isNegativeInRed()
      Returns whether this format shows negative values in red.
    • setNegativeInRed

      public void setNegativeInRed(boolean aFlag)
      Sets whether this format shows negative values in red.
    • getThousandsSeparator

      public String getThousandsSeparator()
      Returns the thousands separator.
    • setThousandsSeparator

      public void setThousandsSeparator(String aValue)
      Sets the thousands separator.
    • getDecimalSeparator

      public String getDecimalSeparator()
      Returns the decimal separator.
    • setDecimalSeparator

      public void setDecimalSeparator(String aValue)
      Sets the decimal separator.
    • getFormatString

      public String getFormatString()
      Returns the format string for this format. This is basically the default toPattern() of DecimalFormat, except that it allows for a arbitrary decimal and grouping separators.
      Specified by:
      getFormatString in interface RMFormat
    • setFormatString

      public void setFormatString(String aFormat)
      Sets the format string for this format. This is basically the default applyPattern() of DecimalFormat, except that it allows for arbitrary decimal and grouping separators.
      Specified by:
      setFormatString in interface RMFormat
    • formatRM

      public Object formatRM(Object anObj)
      Returns a formatted version of the given object.
      Specified by:
      formatRM in interface RMFormat
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class DecimalFormat
    • toXML

      public RXElement toXML(RXArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface RMFormat
    • fromXML

      public Object fromXML(RXArchiver anArchiver, RXElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface RMFormat
    • initWithArchiver

      public Object initWithArchiver(RMArchiver anArchiver)
      Legacy archival.
      Specified by:
      initWithArchiver in interface RMArchiver.Archiving