更精确地使用浮点数
来源:互联网 发布:韩国ip地址和端口 编辑:程序博客网 时间:2024/06/01 08:21
public static void main(String args[])
{
double money=2;
double price=1.1;
double result=money-price;
System.out.println("非精确计算:");
System.out.println("剩余金额:"+result);
//精确浮点数的解决方法
BigDecimal money1=new BigDecimal("5");
BigDecimal price1=new BigDecimal("1.4");
BigDecimal result1=money1.subtract(price1);
System.out.println("精确计算:");
System.out.println("剩余金额:"+result1);
}
{
double money=2;
double price=1.1;
double result=money-price;
System.out.println("非精确计算:");
System.out.println("剩余金额:"+result);
//精确浮点数的解决方法
BigDecimal money1=new BigDecimal("5");
BigDecimal price1=new BigDecimal("1.4");
BigDecimal result1=money1.subtract(price1);
System.out.println("精确计算:");
System.out.println("剩余金额:"+result1);
}
阅读全文
0 0
- 更精确地使用浮点数
- 更精确地进行浮点数计算
- 更精确的使用浮点数
- 更精确的使用浮点型
- Java基础应用之运算符(更精确的使用浮点数)
- 浮点数精确计算
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 精确表达浮点数
- 浮点数精确位数
- 使用ThreadMXBean更精确地评估Thread占用时间
- Android的四种启动方式
- phpstorm使用记录贴
- 密码存储中MD5的安全问题与替代方案
- Java编程热门问题总结——编程技巧篇
- FireBird C# 帮助类
- 更精确地使用浮点数
- 利用nohup来开启python文件
- jQuery Mobile 网格
- iOS UITableViewCell 改变系统选中按钮(UITableViewCellEditControl)的默认图片和位置
- 20170601学习笔记整理
- qml text 显示数字缺少位数解决。
- MySQL Limit 分页优化
- ShareSdk踩坑记
- S3C6410 MFC H264 解码分析