Android(安卓)字符串格式化 千位符
16lz
2021-12-04
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!// ┃ ┗━━━━━━━━━┓// ┃ ┣┓// ┃ ┏┛// ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛// ┃ ┫ ┫ ┃ ┫ ┫// ┗━┻━┛ ┗━┻━┛
更多相关文章
- android学习笔记
- android AutoCompleteTextView
- android Draw
- 【转】Android(安卓)字符串的加密和解密
- 2010.11.28(2)———android 展示网页 和 调用js代码
- 2010.11.28(2)———android 展示网页 和 调用js代码
- android edittext属性说明
- AndroidManifest.xml【 manifest -> permission-tree 和 manifes
- Android(安卓)创建悬停通知栏