01: /* Integers.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Feb 24 21:25:22 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: import java.math.BigDecimal;
22: import java.util.Locale;
23:
24: /**
25: * Integer utilities.
26: *
27: * @author tomyeh
28: */
29: public class Integers {
30: /** The zero. */
31: public static final Integer ZERO = Objects.ZERO_INTEGER;
32:
33: /** urns a String object representing the specified integer, with
34: * the (at-least) specified digits.
35: *
36: * <p>Example: toStringByScale(123, 5) returns "00123",
37: * toStringByScale(123, 2) returns "123".
38: */
39: public static final String toStringByScale(int val, int digits) {
40: String sval = Integer.toString(val);
41: int df = digits - sval.length();
42: if (df <= 0)
43: return sval;
44:
45: final StringBuffer sb = new StringBuffer(digits);
46: while (--df >= 0)
47: sb.append('0');
48: return sb.append(sval).toString();
49: }
50: }
|