* <ul>\r
* <li>If this argument is omitted, this function uses the minimum number of characters necessary.</li>\r
* <li>If this function requires more than places characters, it returns the #NUM! error value.</li>\r
- * <li>If this argument is nonnumeric, this function returns the #VALUE! error value.</li>\r
+ * <li>If this argument is non numeric, this function returns the #VALUE! error value.</li>\r
* <li>If this argument is negative, this function returns the #NUM! error value.</li>\r
* <li>If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.</li>\r
* </ul>\r
*/\r
public final class Dec2Hex extends Var1or2ArgFunction implements FreeRefFunction {\r
\r
- private final static long MIN_VALUE = new Long("-549755813888").longValue();\r
- private final static long MAX_VALUE = new Long("549755813887").longValue();\r
- private final static int DEFAULT_PLACES_VALUE = 10;;\r
+ public static final FreeRefFunction instance = new Dec2Hex();\r
+\r
+ private final static long MIN_VALUE = Long.parseLong("-549755813888");\r
+ private final static long MAX_VALUE = Long.parseLong("549755813887");\r
+ private final static int DEFAULT_PLACES_VALUE = 10;\r
\r
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval number, ValueEval places) {\r
ValueEval veText1;\r
int placesNumber = 0;\r
if (number1 < 0) {\r
placesNumber = DEFAULT_PLACES_VALUE;\r
- } else {\r
+ }\r
+ else if (places != null) {\r
ValueEval placesValueEval;\r
try {\r
placesValueEval = OperandResolver.getSingleValue(places, srcRowIndex, srcColumnIndex);\r
}\r
}\r
\r
- String hex = "";\r
+ String hex;\r
if (placesNumber != 0) {\r
- hex = String.format("%0"+placesNumber+"X", number1.intValue() & 0x0FFFFF);\r
+ hex = String.format("%0"+placesNumber+"X", number1.intValue());\r
}\r
else {\r
hex = Integer.toHexString(number1.intValue());\r
}\r
\r
+ if (number1 < 0) {\r
+ hex = "FF"+ hex.substring(2);\r
+ }\r
+\r
return new StringEval(hex.toUpperCase());\r
}\r
\r
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {\r
- return this.evaluate(srcRowIndex, srcColumnIndex, arg0, new StringEval(String.valueOf(DEFAULT_PLACES_VALUE)));\r
+ return this.evaluate(srcRowIndex, srcColumnIndex, arg0, null);\r
}\r
\r
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {\r
- if (args.length != 2) {\r
- return ErrorEval.VALUE_INVALID;\r
+ if (args.length == 1) {\r
+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0]);\r
}\r
- return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);\r
+ if (args.length == 2) {\r
+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);\r
+ }\r
+ return ErrorEval.VALUE_INVALID;\r
}\r
-\r
-}
\ No newline at end of file
+}\r