n_nn0_2, n_nn 추가

master
mjkhan21 8 months ago
parent 462a985ff4
commit 728d527752

@ -1,5 +1,7 @@
package cokr.xit.foundation.data; package cokr.xit.foundation.data;
import java.text.DecimalFormat;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
public class DataFormat extends AbstractComponent { public class DataFormat extends AbstractComponent {
@ -76,4 +78,35 @@ public class DataFormat extends AbstractComponent {
return str; return str;
} }
} }
private static final DecimalFormat numberFormat = new DecimalFormat("#,##0.00");
/** #,##0.00 .
* @param obj
* @return #,##0.00
*/
public static final String n_nn0_2(Object obj) {
Number num = null;
if (obj == null)
num = 0;
else if (obj instanceof String)
num = Double.valueOf((String)obj);
else if (obj instanceof Number)
num = (Number)obj;
else
throw new IllegalArgumentException(obj + " is not a number");
return numberFormat.format(num);
}
/** #,##0 .
* @param obj
* @return #,##0
*/
public static final String n_nn0(Object obj) {
String str = n_nn0_2(obj);
int pos = str.indexOf(".");
return pos < 0 ? str : str.substring(0, pos);
}
} }
Loading…
Cancel
Save