01: /* Longs.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Wed Feb 25 10:42:53 2004, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2004 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.lang;
20:
21: /**
22: * Long relevant utilities.
23: *
24: * @author tomyeh
25: */
26: public class Longs {
27: /** The zero. */
28: public static final Long ZERO = Objects.ZERO_LONG;
29:
30: /** urns a String object representing the specified integer, with
31: * the (at-least) specified digits.
32: *
33: * <p>Example: toStringByScale(123, 5) returns "00123",
34: * toStringByScale(123, 2) returns "123".
35: */
36: public static final String toStringByScale(long val, int digits) {
37: String sval = Long.toString(val);
38: int df = digits - sval.length();
39: if (df <= 0)
40: return sval;
41:
42: final StringBuffer sb = new StringBuffer(digits);
43: while (--df >= 0)
44: sb.append('0');
45: return sb.append(sval).toString();
46: }
47: }
|