Class NumericLiteralTypes
Measured on a real account by declaring each literal into a table and reading
INFORMATION_SCHEMA back: 1.5 and 0.5 are NUMBER(2,1), 0.05 NUMBER(3,2),
100.25 NUMBER(5,2), 1 NUMBER(1,0), 100 NUMBER(3,0),
0.0000000001 NUMBER(11,10) and 12345678901234567890 NUMBER(20,0). Trailing zeros do
not count — 1.50 is NUMBER(2,1) and 0.000 is NUMBER(1,0), storing plain 0 —
and an exponent is folded in before measuring, so 1.5e2 is NUMBER(3,0) holding 150. A leading
. behaves as a zero integer part: .5 is NUMBER(2,1). The sign is not a digit:
-1.5 is NUMBER(2,1).
So: normalise, take the scale (never negative), and add the integer digits with a floor of one —
a value below 1 still reports the leading zero that 0.05 -> NUMBER(3,2) shows.
This matters beyond metadata. The inferred type becomes a derived relation's real column type, so a
scale-0 NUMBER there does not merely misreport 0.05 — it STORES it as 0.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalexactValue(String text) The exact value a numeric literal's SOURCE TEXT stands for, in plain notation.static booleanexceedsExactRange(BigDecimal value) Whether an exact value needs MORE digits than a NUMBER can hold, which is what takes a literal out of the fixed-point family altogether: live answers1e37as NUMBER(38,0) and1e38— one digit wider — as a DOUBLE, and does the same for the point spelling at thirty-nine digits.static NumericTypeforDecimal(BigDecimal value) The NUMBER type of an exact decimal value.static NumericTypeThe NUMBER type of a numeric literal value, or null when it is not one we can measure.
-
Method Details
-
of
The NUMBER type of a numeric literal value, or null when it is not one we can measure. -
exactValue
The exact value a numeric literal's SOURCE TEXT stands for, in plain notation.An exponent is a way of WRITING a fixed-point number, not a floating-point marker: live prints
1e20back as 100000000000000000000 and1e-3as 0.001.BigDecimalkeeps a negative scale for the first of those and would render it as1E+20, so the scale is raised to zero — the value is unchanged and only its spelling becomes the one live uses.- Parameters:
text- the literal exactly as written- Returns:
- its value
-
forDecimal
The NUMBER type of an exact decimal value. -
exceedsExactRange
Whether an exact value needs MORE digits than a NUMBER can hold, which is what takes a literal out of the fixed-point family altogether: live answers1e37as NUMBER(38,0) and1e38— one digit wider — as a DOUBLE, and does the same for the point spelling at thirty-nine digits. The notation decides nothing; only the magnitude does.Trailing zeros are stripped first, for the reason
forDecimal(java.math.BigDecimal)strips them: a literal written99…9.0with thirty-eight nines is a thirty-eight digit number, and counting its dropped.0would push it over a boundary live keeps it inside.- Parameters:
value- the literal's exact value- Returns:
- whether it is past the exact range
-