有些财务业务场景是需要把数字多余的0去掉的。

可以这么写

private String getRealData(BigDecimal num) {
if (num == null) {
return "0";
}
String value = num.stripTrailingZeros().toString();
return value;
}

也可以这么写

private String getRealData(BigDecimal num) {
if (num == null) {
return "0";
}
String value = new BigDecimal(num.doubleValue()).toString();
String[] temp = value.split("\\.");
if (temp[1].equals("0")) {
return temp[0];
}
return value;
}

java去掉数字后面的0的更多相关文章

  1. java去除字符串后面的\0

    java去除字符串后面的\0 private String filterCode(String string) { if (string != null) { string = string.trim ...

  2. JAVA去掉字符串前面的0

    最佳方案:使用正则 String str = "000000001234034120"; String newStr = str.replaceAll("^(0+)&qu ...

  3. 将decimal类型的数值后面的0和.号去掉

    今天在群里面看到有朋友在问如下的需求,想到以前在写项目时也遇到这种处理数值的需求,所以写一个例子贴在博客里. 需求:在许多显示货币值时,可能需要截取掉后面的0,显示小数值或者整型值. 举例:(1)数据 ...

  4. 黄聪:Dsicuz x2.5、X3、X3.2如何去掉域名后面的/forum.php

    Dsicuz x2.5去掉域名后面的/forum.php 1, 后台--全局--域名设置--应用域名--设置默认域名为访问域名就可以,如:www.xxxxx.com 上面2种方法都可以去掉域名后面的/ ...

  5. C# String.Format大全 去 decimal 后面的 0

    转 http://kwon.iteye.com/blog/1068255  http://blog.csdn.net/tvvbbb/article/details/47256943 public st ...

  6. 去掉url后面的#

    <a href="#" 这个代码,当你点击后会在url后面添加# 怎么去掉呢?解决方法:点击这里 <a href="javascript:void(0)&qu ...

  7. js 去掉字符串前面的0

    <script>var a='00123';alert(a.replace(/\b(0+)/gi,""));</script>

  8. magento去掉小数点后面的0

     <?php echo $_product->getPrice()?> PHP number_format() 函数  <?php echo number_format($_p ...

  9. Laravel 去掉访问后面的 “public”

    将laravel/server.PHP 改名为index.php,再将public目录下的.htaccess拷贝到Larvael根目录下,再访问Larvael就会发现不需要加上public,由于访问入 ...

随机推荐

  1. 洛谷 P2370 yyy2015c01的U盘

    题目传送门 解题思路: 先将每个文件按照占空间从小到大排序,然后跑背包,当到了某一个文件时,价值够了,那么当前文件的体积就是答案. 其实本题是可以二分答案的,但是写挂了... AC代码: #inclu ...

  2. Swift—UITextField的基本用法

    https://www.jianshu.com/p/63bdeca39ddf 1.文本输入框的创建##### let textField = UITextField(frame: CGRect(x:1 ...

  3. 吴裕雄--天生自然Django框架开发笔记:Django 安装

    Window 下安装 Django 如果你还未安装Python环境需要先下载Python安装包. 1.Python 下载地址:https://www.python.org/downloads/ 2.D ...

  4. idea以yarn-client 提交任务到yarn

    鉴于很多小白经常问我如何用idea提交任务到yarn,这样测试的时候不用频繁打包. 昨天,晚上健身回来录了一个小视频,说是小视频但是耗时也比较长,将近40min.可能是健身脱水太多,忘了补充盐分,无力 ...

  5. PAT Advanced 1030 Travel Plan (30) [Dijkstra算法 + DFS,最短路径,边权]

    题目 A traveler's map gives the distances between cities along the highways, together with the cost of ...

  6. PAT Advanced 1151 LCA in a Binary Tree (30) [树的遍历,LCA算法]

    题目 The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both ...

  7. 记校赛水题----AK爷兼职计

    Description AK爷最近收到一份兼职,是去幼儿园看小朋友,AK爷认为看孩子这件事情很简单,但是事实并非如此.幼儿园里的孩子们喜欢数学,不仅九九乘法口诀倒背如流而且精通各种算法.某天,AK爷上 ...

  8. JAVA函数库

    1. 文件相关 1.1 判断目录是否存在 public static boolean dictionaryExist(String path) { File file = new File(path) ...

  9. POJ 1502:MPI Maelstrom Dijkstra模板题

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6499   Accepted: 4036 Des ...

  10. nginx重写常用写法

    1.将http协议重写成https协议: (用户用http进行访问,但后端是https),则可添加80 http端口监听,然后进行https rewrite; server {     listen ...