java中保留几位小数
public class NumUtils {
/**
* 保留两位小数
*
* @param d
* @return
*/
public static String get2Wei(double d) {
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
return df.format(d);
}
/**
* 保留两位小数
*
* @param d
* @return
*/
public static String get2Wei(Float d) {
if (d == null)
return "0";
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
return df.format(d);
}
/**
* 保留0位小数
*
* @param d
* @return
*/
public static String get0Wei(double d) {
java.text.DecimalFormat df = new java.text.DecimalFormat("#");
return df.format(d);
}
/**
* 保留0位小数
*
* @param d
* @return
*/
public static String get0Wei(Float d) {
if (d == null)
return "0";
java.text.DecimalFormat df = new java.text.DecimalFormat("#");
return df.format(d);
}
}
java中保留几位小数的更多相关文章
- java中保留两位小数的方法
1.BigDecimal的setScale // RoundingMode 舍入模式: // 1.UP/DOWN ->基准为数字0: // 2.CEILING/FLOOR ->基准为正负无 ...
- Java float保留两位小数或多位小数
Java float保留两位小数或多位小数 方法1:用Math.round计算,这里返回的数字格式的. float price=89.89;int itemNum=3;float totalPr ...
- Oracle中保留两位小数
在最近的项目开发中,有个业务需求是界面显示的数字需要保留两位小数,目前我想到的解决方法有两种: (1)在写SQL的时候,直接保留两位小数 (2)在java代码里面将查询出来的数进行格式化处理,保留两位 ...
- java double 保留两位小数
java保留两位小数问题: 方式一: 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); d ...
- sql中保留一位小数的百分比字符串拼接,替换函数,换行符使用
select num ,cast(round(convert(float,isnull((a.Sum_Num-d.Sum_Num),0))/convert(float,c.Sum_Store_Num ...
- Python中保留两位小数的几种方法
https://blog.csdn.net/Jerry_1126/article/details/85009810 保留两位小数,并做四舍五入处理方法一: 使用字符串格式化>>> a ...
- C#中保留两位小数但不四舍五入的最优做法
多种做法比较 class Program_保留两位小数但不四舍五入 { static void Main(string[] args) { Helper.Run(delegate () { metho ...
- java 四舍五入保留两位小数
// 保留两位小数 System.out.println(Double.parseDouble(String.format("%.2f", 55.5454545454))); // ...
- sql中保留2位小数
问题: 数据库里的 float momey 类型,都会精确到多位小数.但有时候 我们不需要那么精确,例如,只精确到两位有效数字. 解决: 1. 使用 Round() 函数,如 Round(@num,2 ...
随机推荐
- location对象,将url解析为独立片段search属性截取传递的参数
通过location对象的search属性截取字符串传递过来的参数 search ?item=hello&name=auto&age=25 返回url中传递的参数,以?开头 funct ...
- DEDE站点从网站根目录移到子目录
修改DedeCms系统配置参数-站点设置 a.站点根网址修改为:http://域名/子目录 b.网页主页链接:/子目录 修改DedeCms系统配置参数-核心设置 a.安装目录:/子目录 批量修改原数据 ...
- VISUAL STUDIO 2005连接MYSQL数据库
// mysql.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <string.h> #include &l ...
- codevs4373 窗口
题目描述 Description 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右移动一位,如下表: Window position Min val ...
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath
1.Request.ApplicationPath->当前应用的目录 2.Request.FilePath->对应于iis的虚拟目录 如 URL http://mockte.com/1 ...
- mongoose CastError: Cast to ObjectId failed for value
restfull路由如下: router.get('/:id', controller.show); mongoes代码如下: exports.show = function(req, res) { ...
- Eclipse里的智能提示
Eclipse 3.1里的智能提示功能对于写JAVA程序又不记得类名和函数的人来说是一个很好的助手工具,但是Eclipse里的智能提示的快捷键是Ctrl+Space,在中文Windows操作系统中它确 ...
- BeautifulSoup解析非标准HTML的问题
发现问题: BeautifulSoup版本:4.3.2 在用BeautifulSoup.find_all()搜索HTML时,遇到下面的代码: <a href="/shipin/dong ...
- 自己的缺省(sheng)源
write无力吐槽了 #include <cstdio> #include <iostream> #include <algorithm> #include < ...
- 八、频繁模式挖掘Frequent Pattern Mining
频繁模式挖掘(Frequent Pattern Mining): 频繁项集挖掘是通常是大规模数据分析的第一步,多年以来它都是数据挖掘领域的活跃研究主题.建议用户参考维基百科的association r ...