What you will do
You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.
How it works
CEL provides int, uint, and double numeric types, and arithmetic requires matching types. JSON has only one general number syntax, so this playground maps JSON numbers to CEL double. The self-contained example therefore writes 3.0, not 3, beside 12.5. Integer division truncates toward zero, while double division keeps the fractional part.
Read the prepared example
The CEL + JSON rule is:
price * quantity - discountIts input is:
{
"price": 12.5,
"quantity": 3,
"discount": 3
}The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.
Evaluation step by step
12.5 * 3.0produces37.5.37.5 - 3.0produces34.5.- The final type is
double.
Your task
- Run both modes and confirm
34.5. - Try
7 / 2in CEL only. - Then try
7.0 / 2.0and compare the results.
Expected observation: 7 / 2 returns 3; 7.0 / 2.0 returns 3.5.
Common mistake
Writing 12.5 * 3 mixes double and int. CEL requires an explicit choice instead of silently widening one operand.
Show the explanation
It makes the quantity a double, matching the price and discount.
Knowledge check
Why is the quantity written as 3.0 in the self-contained example?
Key takeaway
Choose a numeric type deliberately, keep arithmetic operands compatible, and convert only where the data boundary requires it.
Sources
CEL-DEV— official CEL overview.CEL-LANG— official CEL language definition.CEL-GO-BIND— official documentation for the optionalcel.bind()extension used by the self-contained tab.