Package app.babylon.text
Class BigDecimals
java.lang.Object
app.babylon.text.BigDecimals
Parsing and extraction helpers for decimal text values.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPolicy used to resolve ambiguous decimal separators.static final classstatic final classPrepared decimal text together with formatting flags discovered during normalisation. -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalextract(CharSequence sentence) Deprecated, for removal: This API element is subject to removal in a future version.static DoubleextractDouble(CharSequence sentence) Deprecated, for removal: This API element is subject to removal in a future version.useSentence.ParseMode.ONLY_INwithparseDouble(CharSequence)insteadstatic booleanReturns whether the supplied text could represent a decimal.static booleanisWholeNumber(BigDecimal value) static BigDecimalparse(char[] chars, int start, int end) Parses a decimal value from a character array slice, preserving the parsed decimal scale.static BigDecimalparse(char[] chars, int start, int end, boolean stripTrailingZeros) static BigDecimalparse(ByteSequence bytes, int start, int end) Parses a decimal value directly from a byte sequence slice, preserving the parsed decimal scale.static BigDecimalparse(ByteSequence bytes, int start, int end, boolean stripTrailingZeros) Parses a decimal value directly from a byte sequence slice.static BigDecimalParses a decimal value from the supplied text, preserving the parsed decimal scale.static BigDecimalparse(CharSequence s, boolean stripTrailingZeros) Parses a decimal value from the supplied text.static BigDecimalparse(CharSequence s, int start, int end) Parses a decimal value from a character slice, preserving the parsed decimal scale.static BigDecimalparse(CharSequence s, int start, int end, boolean stripTrailingZeros) Parses a decimal value from a character slice.static BigDecimalparse2(CharSequence s, int start, int end) Parses a decimal value from a slice of the supplied text.static BigDecimalparse2(CharSequence s, int start, int end, BigDecimals.DecimalPolicy policy) Parses a decimal value from a slice of the supplied text.static DoubleParses aDoublefrom the supplied text.static BigDecimals.ParsedDecimalparseLazy(CharSequence s, int start, int end) static BigDecimals.PreparedDecimalNormalises a decimal candidate before final parsing.static StringRemoves commas from a simple numeric string, leaving other text unchanged.
-
Method Details
-
isDecimal
Returns whether the supplied text could represent a decimal.- Parameters:
s- text to inspect- Returns:
truewhen the text can be normalised as a decimal
-
removeCommas
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
Parses a decimal value from the supplied text, preserving the parsed decimal scale.Use
parse(CharSequence, boolean)to strip trailing zeros.- Parameters:
s- text to parse- Returns:
- parsed decimal or
null
-
parse
Parses a decimal value from the supplied text.- Parameters:
s- text to parsestripTrailingZeros- whether to normalise the parsed decimal by stripping trailing zeros- Returns:
- parsed decimal or
null
-
parse
Parses a decimal value from a character slice, preserving the parsed decimal scale.Use
parse(CharSequence, int, int, boolean)to strip trailing zeros.- Parameters:
s- text to parsestart- inclusive start indexend- exclusive end index- Returns:
- parsed decimal or
null
-
parse
Parses a decimal value from a character slice.- Parameters:
s- text to parsestart- inclusive start indexend- exclusive end indexstripTrailingZeros- whether to normalise the parsed decimal by stripping trailing zeros- Returns:
- parsed decimal or
null
-
parse
Parses a decimal value from a character array slice, preserving the parsed decimal scale.Use
parse(char[], int, int, boolean)to strip trailing zeros.- Parameters:
chars- characters containing the decimal textstart- inclusive start indexend- exclusive end index- Returns:
- parsed decimal or
null
-
parse
-
parse
Parses a decimal value directly from a byte sequence slice, preserving the parsed decimal scale.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
Stringbefore 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
123,456are treated as grouped thousands, while non-ambiguous values such as123,45are treated as comma-decimal values.- Parameters:
bytes- byte sequence containing the decimal textstart- inclusive start indexend- exclusive end index- Returns:
- parsed decimal or
null - See Also:
- plain decimal:
-
parse
Parses a decimal value directly from a byte sequence slice.- Parameters:
bytes- byte sequence containing the decimal textstart- inclusive start indexend- exclusive end indexstripTrailingZeros- whether to normalise the parsed decimal by stripping trailing zeros- Returns:
- parsed decimal or
null
-
parse2
Parses a decimal value from a slice of the supplied text.- Parameters:
s- text to parsestart- inclusive start indexend- exclusive end index- Returns:
- parsed decimal or
null
-
parseLazy
-
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 parsestart- inclusive start indexend- exclusive end indexpolicy- decimal separator policy- Returns:
- parsed decimal or
null
-
parseDouble
Parses aDoublefrom 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.useSentence.ParseMode.ONLY_INwithparse(CharSequence)insteadExtracts a single decimal value from a sentence-like string.- Parameters:
sentence- source text- Returns:
- parsed decimal or
nullif 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.useSentence.ParseMode.ONLY_INwithparseDouble(CharSequence)insteadExtracts a single double value from a sentence-like string.- Parameters:
sentence- source text- Returns:
- parsed double or
nullif none or more than one are found
-
prepare
Normalises a decimal candidate before final parsing.- Parameters:
s- text to prepare- Returns:
- prepared decimal metadata or
null
-
isWholeNumber
-
Sentence.ParseMode.ONLY_INwithparse(CharSequence)instead