From 728d5277524618095a71b126901355f3510b6431 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Mon, 1 Apr 2024 11:02:38 +0900 Subject: [PATCH] =?UTF-8?q?n=5Fnn0=5F2,=20n=5Fnn=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/foundation/data/DataFormat.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/cokr/xit/foundation/data/DataFormat.java b/src/main/java/cokr/xit/foundation/data/DataFormat.java index a65a2e1..738c8b2 100644 --- a/src/main/java/cokr/xit/foundation/data/DataFormat.java +++ b/src/main/java/cokr/xit/foundation/data/DataFormat.java @@ -1,5 +1,7 @@ package cokr.xit.foundation.data; +import java.text.DecimalFormat; + import cokr.xit.foundation.AbstractComponent; public class DataFormat extends AbstractComponent { @@ -76,4 +78,35 @@ public class DataFormat extends AbstractComponent { 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); + } } \ No newline at end of file