apache/cassandra · error · InvalidTypeException
Cannot parse decimal value from "%s"
Error message
Cannot parse decimal value from "%s"
What it means
The decimal codec's parse() delegates to new BigDecimal(value); strings that are not valid decimal representations raise NumberFormatException, rethrown as InvalidTypeException. Valid forms are optional sign, digits with optional decimal point and exponent — like CQL decimal literals.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1310
private static final DecimalCodec instance = new DecimalCodec();
private DecimalCodec()
{
super(DataType.decimal(), BigDecimal.class);
}
@Override
public BigDecimal parse(String value)
{
try
{
return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
? null
: new BigDecimal(value);
}
catch (NumberFormatException e)
{
throw new InvalidTypeException(
String.format("Cannot parse decimal value from \"%s\"", value));
}
}
@Override
public String format(BigDecimal value)
{
if (value == null) return "NULL";
return value.toString();
}
@Override
public ByteBuffer serialize(BigDecimal value, ProtocolVersion protocolVersion)
{
if (value == null) return null;
BigInteger bi = value.unscaledValue();
int scale = value.scale();
byte[] bibytes = bi.toByteArray();View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Normalize the string: strip currency symbols and grouping separators, convert the decimal comma to a dot, trim whitespace.
- Use a NumberFormat with the correct Locale and parse to BigDecimal, then pass its toPlainString().
- Use codec.format(BigDecimal) when starting from a real BigDecimal instead of a string.
Example fix
// before
decimalCodec.parse("1.234,56"); // throws (NumberFormatException)
// after
String normalized = "1.234,56".replace(".", "").replace(',', '.'); // "1234.56"
decimalCodec.parse(normalized); Defensive patterns
Strategy: validation
Validate before calling
static boolean isCqlDecimalLiteral(String v) {
return v != null && v.trim().matches("^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$" );
} Type guard
boolean isDecimalLiteral(String v) {
if (v == null) return false;
try { new BigDecimal(v.trim()); return true; } catch (NumberFormatException e) { return false; }
} Try / catch
try {
return decimalCodec.parse(raw);
} catch (InvalidTypeException e) {
String norm = raw.replace(".", "").replace(',', '.').trim();
return decimalCodec.parse(norm);
} Prevention
- Normalize locale-specific formats (decimal comma, grouping separators, currency symbols) before parsing.
- Prefer building BigDecimal objects in code and using codec.format().
- Pre-validate with new BigDecimal(s) in a try/catch helper.
When it happens
Trigger: Calling decimalCodec.parse(value) with non-numeric or malformed strings such as "abc", "1,234.5", "1.2.3", empty-after-NULL-check tokens, or locale-formatted numbers.
Common situations: CSV/JSON imports with thousands separators or comma decimal points (European locales); currency symbols in the string; scientific notation from one system pasted where a different syntax is expected; whitespace or invisible characters.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot parse 64-bits double value from "%s"
- Cannot parse 64-bits long value from "%s"
- Cannot parse boolean value from "%s"
- Invalid decimal value, expecting at least 4 bytes but got
- text or varchar values must be enclosed by single quotes
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/686bbc2a3fcb9ee8.
Report an issue: GitHub.