|
@@ -0,0 +1,40 @@
|
|
|
|
+package com.winhc.bigdata.udf.etl;
|
|
|
|
+
|
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
|
+
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: XuJiakai
|
|
|
|
+ * 2022/2/15 09:20
|
|
|
|
+ * 注册资本格式化
|
|
|
|
+ * Ps. 800.000000万元 -> 800万元
|
|
|
|
+ */
|
|
|
|
+public class RegisteredCapitalFormat extends UDF {
|
|
|
|
+ private static final Pattern pattern = Pattern.compile("[^\\x00-\\x7F]+");
|
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("0.###########");
|
|
|
|
+
|
|
|
|
+ public String evaluate(String content) {
|
|
|
|
+ if (StringUtils.isBlank(content)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ String prefix = pattern.matcher(content).replaceAll("");
|
|
|
|
+ String unit = content.replace(prefix, "");
|
|
|
|
+ double v = Double.parseDouble(prefix);
|
|
|
|
+ return decimalFormat.format(v) + unit;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ RegisteredCapitalFormat registeredCapitalFormat = new RegisteredCapitalFormat();
|
|
|
|
+ String evaluate = registeredCapitalFormat.evaluate("0.00000美元");
|
|
|
|
+ System.out.println(evaluate);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|