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网站汇集
  2. android 读取mac地址
  3. Android软键盘(四)软件盘弹出布局上移的问
  4. Android 新加几个开源项目
  5. 系统重置
  6. Android shape属性
  7. android使Activity背景透明、模糊
  8. Android — get MEID
  9. Android Timer 更好方法
  10. bsh for android : 北京