|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.singularsys.jep.functions.PostfixMathCommand com.singularsys.jep.misc.functions.ToBase
public class ToBase
Convert a number to a string in a given base. The base to used is specified in the constructor
A prefix can be specified in the constructor. If set this will be appended to the number (after minus sign for negative values). For example with the following setup
jep.addFunction("toBase",new ToBase()); jep.addFunction("toDec",new ToBase(10)); jep.addFunction("toHex",new ToBase(16,"0x"));
A prefix can be specified in the constructor. If set this will be appended to the number (after minus sign for negative values).
Long.toString(long, int)
,
Serialized FormField Summary |
---|
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand |
---|
curNumberOfParameters, name, NaN, numberOfParameters |
Constructor Summary | |
---|---|
ToBase()
Constructor where base is specified as a function argument. |
|
ToBase(int base)
Constructor with specified base. |
|
ToBase(int base,
java.lang.String prefix)
Constructor with specified base and a given prefix. |
Method Summary | |
---|---|
boolean |
checkNumberOfParameters(int n)
Checks the number of parameters of the function. |
void |
run(java.util.Stack<java.lang.Object> s)
Run the function on the stack. |
java.lang.String |
toBase(double val,
int base,
int digits)
Converts a number to a give base. |
java.lang.String |
toBase(long num,
int base)
Converts a number to a give base. |
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand |
---|
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkStack, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ToBase()
public ToBase(int base)
base
- the base to use
java.lang.IllegalArgumentException
- if base is < 2 or > 36public ToBase(int base, java.lang.String prefix)
base
- the base to useprefix
- the string to prefix numbers with.
java.lang.IllegalArgumentException
- if base is < 2 or > 36Method Detail |
---|
public boolean checkNumberOfParameters(int n)
PostfixMathCommand
checkNumberOfParameters
in interface PostfixMathCommandI
checkNumberOfParameters
in class PostfixMathCommand
n
- number of parameters function will be called with.
public void run(java.util.Stack<java.lang.Object> s) throws EvaluationException
PostfixMathCommandI
EvaluationException
public java.lang.String toBase(long num, int base)
num
- number to convertbase
- base to use
java.lang.IllegalArgumentException
- if base is < 2 or > 36public java.lang.String toBase(double val, int base, int digits)
val
- number to convertbase
- base to usedigits
- number of digits after decimal place
java.lang.IllegalArgumentException
- if base is < 2 or > 36
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |