|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.tools.generic.MathTool
Tool for performing floating point math in Velocity.
Several things should be noted here:
Double
wrappers
which automatically render the decimal places even
for whole numbers (e.g. new Double(1).toString() -> '1.0')
This is intentional. This tool is for floating
point arithmetic. Integer arithmetic is already supported
in Velocity syntax. if you really need '1' instead of '1.0',
just call intValue() on the result.Example toolbox.xml config (if you want to use this with VelocityView): <tool> <key>math</key> <scope>application</scope> <class>org.apache.velocity.tools.generic.MathTool</class> </tool>
Constructor Summary | |
MathTool()
|
Method Summary | |
java.lang.Double |
abs(java.lang.Object num)
|
java.lang.Double |
add(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
div(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
getRandom()
|
java.lang.Double |
max(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
min(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
mul(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
pow(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Integer |
random(java.lang.Object num1,
java.lang.Object num2)
This returns a random Integer within the
specified range. |
java.lang.Double |
roundTo(java.lang.Object decimals,
java.lang.Object num)
Rounds a number to the specified number of decimal places. |
java.lang.Integer |
roundToInt(java.lang.Object num)
Rounds a number to the nearest whole Integer |
java.lang.Double |
sub(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
toDouble(java.lang.Object num)
Converts an object with a numeric value into a Double Valid formats are Number or a String
representation of a number |
java.lang.Integer |
toInteger(java.lang.Object num)
Converts an object with a numeric value into an Integer Valid formats are Number or a String
representation of a number |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MathTool()
Method Detail |
public java.lang.Double add(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double sub(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double mul(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double div(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double pow(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double max(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double min(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoDouble(java.lang.Object)
public java.lang.Double abs(java.lang.Object num)
null
if it's invalidtoDouble(java.lang.Object)
public java.lang.Double toDouble(java.lang.Object num)
Number
or a String
representation of a number
num
- the number to be converted
Double
representation of the number
or null
if it's invalidpublic java.lang.Integer toInteger(java.lang.Object num)
Number
or a String
representation of a number
num
- the number to be converted
Integer
representation of the number
or null
if it's invalidpublic java.lang.Double roundTo(java.lang.Object decimals, java.lang.Object num)
roundToInt(java.lang.Object)
, as that will return
an Integer
rather than a Double
.
decimals
- the number of decimal places
null
if it's invalidtoDouble(java.lang.Object)
,
toInteger(java.lang.Object)
public java.lang.Integer roundToInt(java.lang.Object num)
num
- the number to round
null
if it's invalidtoDouble(java.lang.Object)
public java.lang.Double getRandom()
Double
greater
than or equal to 0.0 and less than 1.0Math.random()
public java.lang.Integer random(java.lang.Object num1, java.lang.Object num2)
Integer
within the
specified range. The return Integer will have a
value greater than or equal to the first number
and less than the second number.
num1
- the first numbernum2
- the second number
Integer
greater than
or equal to the first number and less than
the secondtoInteger(java.lang.Object)
,
Math.random()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |