Android 字符串格式化 千位符

字符串格式化工具类 千位符 & 千位符保留小数点后两位

import java.text.DecimalFormat;import java.text.NumberFormat;import java.text.ParseException;public class StringUtils {    public static boolean isEmpty(String str) {        return str == null || str.trim().length() == 0;    }    /**     * 字符串 千位符     *     * @param num     * @return     */    public static String num2thousand(String num) {        String numStr = "";        if (isEmpty(num)) {            return numStr;        }        NumberFormat nf = NumberFormat.getInstance();        try {            DecimalFormat df = new DecimalFormat("#,###");            numStr = df.format(nf.parse(num));        } catch (ParseException e) {            e.printStackTrace();        }        return numStr;    }    /**     * 字符串 千位符  保留两位小数点后两位     *     * @param num     * @return     */    public static String num2thousand00(String num) {        String numStr = "";        if (isEmpty(num)) {            return numStr;        }        NumberFormat nf = NumberFormat.getInstance();        try {            DecimalFormat df = new DecimalFormat("#,##0.00");            numStr = df.format(nf.parse(num));        } catch (ParseException e) {            e.printStackTrace();        }        return numStr;    }}
//      ┏┛ ┻━━━━━┛ ┻┓//      ┃       ┃//      ┃   ━   ┃//      ┃ ┳┛   ┗┳ ┃//      ┃       ┃//      ┃   ┻   ┃//      ┃       ┃//      ┗━┓   ┏━━━┛//        ┃   ┃   神兽保佑//        ┃   ┃   代码无BUG!//        ┃   ┗━━━━━━━━━┓//        ┃           ┣┓//        ┃             ┏┛//        ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛//          ┃ ┫ ┫   ┃ ┫ ┫//          ┗━┻━┛   ┗━┻━┛

更多相关文章

  1. 【转】Android 字符串的加密和解密
  2. TextUtils类-Android字符串处理类
  3. android 字符串加解密算法
  4. 【Android 应用开发】Android资源文件 - 使用资源存储字符串 颜
  5. Android通过AES128加密解密字符串
  6. 2011.07.11(3)——— android xliff字符串操作
  7. Android EditText保留小数点后两位
  8. android 加密字符串

随机推荐

  1. android studio使用github
  2. [Android学习笔记五] Android View和Widg
  3. Android(OPhone) 学习笔记 - SharedPrefere
  4. What Is Bootloader And How To Unlock B
  5. 基于 Android 的英文电子词典
  6. 2020.8.12 京东Android开发工程师一面面
  7. Android - API Levels-
  8. Android ScrollView中的组件设置android:
  9. Vue实现简书导航栏效果
  10. App测试中Android和IOS测试区别