数字表达式

数字表达式解析为一个数字,可以在各种情况下指定这样的表达式;例如,可以在赋值语句的右边指定数字表达式。数字表达式可以由下列任何内容组成:

可以在数字表达式中使用成对的圆括号来更改求值顺序或明确其含义。

在查看以下示例时,假定 intValue1 等于 1,intValue2 等于 2,依此类推,并且每个值都没有小数位:

  /* == -8, with the parentheses overriding 
                      the usual precedence of * and + */
    intValue2 * (intValue1 - 5)

  /* == -2, with a unary minus as the last operator */ 
    intValue2 + -4  

  /* == 1.4, if the expression is assigned to an 
                        item with at least one decimal place.  */
  intValue7 / intValue5

  /* == 2, which is a remainder 
                    expressed as an integer value */
  intValue7 % intValue5

有关显示圆括号对加号(+)用法的影响的示例,请参阅表达式

如果计算出来的中间值超过 128 位,则数字表达式可能会给出意外的结果。

相关参考
日期时间表达式
表达式
逻辑表达式
运算符和优先顺序
基本类型
文本表达式

使用条款 | 反馈
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.