1 21 22 package org.opensubsystems.core.util; 23 24 import java.text.NumberFormat ; 25 26 34 public final class NumberUtils 35 { 36 38 42 protected static final char[] ZEROCHARS = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 43 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 44 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 45 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 46 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 47 }; 48 49 51 54 public static final NumberFormat NFFORMAT; 55 56 59 public static final NumberFormat NFFORMATEDIT; 60 61 64 public static final NumberFormat NFCURRENCYFORMAT; 65 66 69 public static final NumberFormat NFCURRENCYFORMATEDIT; 70 71 73 76 static 77 { 78 79 NFFORMAT = NumberFormat.getNumberInstance(); 80 NFFORMAT.setMaximumFractionDigits(20); 81 82 NFFORMATEDIT = NumberFormat.getNumberInstance(); 83 NFFORMATEDIT.setMaximumFractionDigits(20); 84 NFFORMATEDIT.setGroupingUsed(false); 85 86 NFCURRENCYFORMAT = NumberFormat.getNumberInstance(); 87 NFCURRENCYFORMAT.setMaximumFractionDigits(2); 88 NFCURRENCYFORMAT.setMinimumFractionDigits(2); 89 90 NFCURRENCYFORMATEDIT = NumberFormat.getNumberInstance(); 91 NFCURRENCYFORMATEDIT.setMaximumFractionDigits(2); 92 NFCURRENCYFORMATEDIT.setMinimumFractionDigits(2); 93 NFCURRENCYFORMATEDIT.setGroupingUsed(false); 94 95 } 96 97 100 private NumberUtils( 101 ) 102 { 103 } 105 106 108 116 public static long exponentiate( 117 int iBbase, 118 int iExponent 119 ) throws IllegalArgumentException  120 { 121 if (iExponent > 14 || iExponent < 0) 122 { 123 throw new IllegalArgumentException ( 124 "Exponent could not be greater then 14 and lower then 0"); 125 } 126 if (iBbase < 1) 127 { 128 throw new IllegalArgumentException ( 129 "Exponentiate base could not be lower then 1"); 130 } 131 long lReturn = 1; 132 for (int iCounter = 0; iCounter < iExponent; iCounter++) 133 { 134 try 135 { 136 lReturn = lReturn * iBbase; 137 } 138 catch (Exception eExc) 139 { 140 throw new IllegalArgumentException ( 141 "Exponentiate arguments too high"); 142 } 143 } 144 return lReturn; 145 } 146 147 159 public static String getDigitNumberString( 160 int iInputNumber, 161 int iDigitLength 162 ) 163 { 164 StringBuffer idString = new StringBuffer (Integer.toString(iInputNumber)); 165 166 if (iDigitLength - idString.length() > 0) 167 { 168 idString.insert(0, ZEROCHARS, 0, iDigitLength - idString.length()); 169 } 170 171 return idString.toString(); 172 } 173 } 174 | Popular Tags |