Class BigDecimals

java.lang.Object
app.babylon.text.BigDecimals

public final class BigDecimals extends Object
Parsing and extraction helpers for decimal text values.
  • Method Details

    • isDecimal

      public static boolean isDecimal(CharSequence s)
      Returns whether the supplied text could represent a decimal.
      Parameters:
      s - text to inspect
      Returns:
      true when the text can be normalised as a decimal
    • removeCommas

      public static String removeCommas(String s)
      Removes commas from a simple numeric string, leaving other text unchanged.
      Parameters:
      s - text to normalise
      Returns:
      comma-free text or the original value when no safe cleanup applies
    • parse

      public static BigDecimal parse(CharSequence s)
      Parses a decimal value from the supplied text.
      Parameters:
      s - text to parse
      Returns:
      parsed decimal or null
    • parse

      public static BigDecimal parse(CharSequence s, int start, int end)
      Parses a decimal value from a character slice.
      Parameters:
      s - text to parse
      start - inclusive start index
      end - exclusive end index
      Returns:
      parsed decimal or null
    • parse

      public static BigDecimal parse(char[] chars, int start, int end)
    • parse

      public static BigDecimal parse(ByteSequence bytes, int start, int end)
      Parses a decimal value directly from a byte sequence slice.

      This method is intended for high-throughput tabular input, especially CSV parsing, where a numeric field may already be available as bytes and should not need to be decoded into a String before parsing. It is deliberately flexible about common financial text formats while still rejecting malformed grouping or misplaced formatting characters.

      Accepted styles include:

      • plain decimal: 1234.56
      • leading minus: -1234.56
      • leading decimal point: .56
      • trailing decimal point: 1234.
      • currency prefix: R1234.56
      • currency suffix: 1234.56R
      • bracket negative: (1234.56)
      • currency plus bracket negative: R(1234.56), (R1234.56), (1234.56)R
      • percent: 1234.56%
      • period decimal with comma grouping: 1,234.56, 1,234,567.89
      • comma decimal with period grouping: 1.234,56, 1.234.567,89
      • comma decimal with regular-space grouping: 1 234,56, 1 234 567,89
      • period decimal with regular-space grouping: 1 234.56, 1 234 567.89
      • integer with comma grouping: 1,234, 1,234,567
      • integer with period grouping: 1.234, 1.234.567
      • integer with regular-space grouping: 1 234, 1 234 567
      • Latin-1 non-breaking-space grouping: 1 234.56
      • UTF-8 non-breaking-space grouping: 1 234.56
      • UTF-8 narrow non-breaking-space grouping: 1 234.56
      Spaces and non-breaking spaces are grouping separators only; only comma and period may act as decimal separators. Ambiguous single comma values such as 123,456 are treated as grouped thousands, while non-ambiguous values such as 123,45 are treated as comma-decimal values.
      Parameters:
      bytes - byte sequence containing the decimal text
      start - inclusive start index
      end - exclusive end index
      Returns:
      parsed decimal or null
    • parse2

      public static BigDecimal parse2(CharSequence s, int start, int end)
      Parses a decimal value from a slice of the supplied text.
      Parameters:
      s - text to parse
      start - inclusive start index
      end - exclusive end index
      Returns:
      parsed decimal or null
    • parseLazy

      public static BigDecimals.ParsedDecimal parseLazy(CharSequence s, int start, int end)
    • parse2

      public static BigDecimal parse2(CharSequence s, int start, int end, BigDecimals.DecimalPolicy policy)
      Parses a decimal value from a slice of the supplied text.
      Parameters:
      s - text to parse
      start - inclusive start index
      end - exclusive end index
      policy - decimal separator policy
      Returns:
      parsed decimal or null
    • parseDouble

      public static Double parseDouble(CharSequence s)
      Parses a Double from the supplied text.
      Parameters:
      s - text to parse
      Returns:
      parsed double or null
    • extract

      @Deprecated(since="0.3.25", forRemoval=true) public static BigDecimal extract(CharSequence sentence)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Sentence.ParseMode.ONLY_IN with parse(CharSequence) instead
      Extracts a single decimal value from a sentence-like string.
      Parameters:
      sentence - source text
      Returns:
      parsed decimal or null if none or more than one are found
    • extractDouble

      @Deprecated(since="0.3.25", forRemoval=true) public static Double extractDouble(CharSequence sentence)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Sentence.ParseMode.ONLY_IN with parseDouble(CharSequence) instead
      Extracts a single double value from a sentence-like string.
      Parameters:
      sentence - source text
      Returns:
      parsed double or null if none or more than one are found
    • prepare

      public static BigDecimals.PreparedDecimal prepare(CharSequence s)
      Normalises a decimal candidate before final parsing.
      Parameters:
      s - text to prepare
      Returns:
      prepared decimal metadata or null
    • isWholeNumber

      public static boolean isWholeNumber(BigDecimal value)