📄 coercenumber.html
字号:
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Interpreting Objects as Numbers</title><link href="../docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.65.0" name="generator"><link rel="home" href="index.html" title="OGNL Language Guide"><link rel="up" href="coercion.html" title="Chapter 5. Coercing Objects to Types"><link rel="previous" href="coercion.html" title="Chapter 5. Coercing Objects to Types"><link rel="next" href="coerceInteger.html" title="Interpreting Objects as Integers"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Interpreting Objects as Numbers</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="coercion.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><th align="center" width="60%">Chapter 5. Coercing Objects to Types</th><td align="right" width="20%"> <a accesskey="n" href="coerceInteger.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="coerceNumber"></a>Interpreting Objects as Numbers</h2></div></div><div></div></div><p>Numerical operators try to treat their arguments as numbers. The basic primitive-type wrapper classes (Integer, Double, and so on, including Character and Boolean, which are treated as integers), and the "big" numeric
classes from the java.math package (BigInteger and BigDecimal), are recognized as special numeric types. Given an object of some other class, <span class="acronym">OGNL</span> tries to parse the object's string value as a number.</p><p>Numerical operators that take two arguments use the following algorithm to decide what type the result should be. The type of the actual result may be wider, if the result does not fit in the given type.</p><div class="itemizedlist"><ul type="disc"><li><p>If both arguments are of the same type, the result will be of the same type if possible.</p></li><li><p>If either argument is not of a recognized numeric class, it will be treated as if it was a <tt class="classname">Double</tt> for the rest of this algorithm.</p></li><li><p>If both arguments are approximations to real numbers <tt class="classname">(Float</tt>, <tt class="classname">Double</tt>, or <tt class="classname">BigDecimal</tt>), the result will be the wider type.</p></li><li><p>If both arguments are integers <tt class="classname">(Boolean</tt>, <tt class="classname">Byte</tt>, <tt class="classname">Character</tt>, <tt class="classname">Short</tt>, <tt class="classname">Integer</tt>, <tt class="classname">Long</tt>, or
<tt class="classname">BigInteger</tt>), the result will be the wider type.</p></li><li><p>If one argument is a real type and the other an integer type, the result will be the real type if the integer is narrower than "int"; <tt class="classname">BigDecimal</tt> if the integer is <tt class="classname">BigInteger</tt>;
or the wider of the real type and <tt class="classname">Double</tt> otherwise.</p></li></ul></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="coercion.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><td align="center" width="20%"><a accesskey="u" href="coercion.html"><img src="../images/navigation/up.gif" alt="Up"></a></td><td align="right" width="40%"> <a accesskey="n" href="coerceInteger.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">Chapter 5. Coercing Objects to Types </td><td align="center" width="20%"><a accesskey="h" href="index.html"><img src="../images/navigation/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%"> Interpreting Objects as Integers</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -