Poj_1004_FinancialManagement
一、Description
first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his
average account balance.
Input
Output
no other spaces or characters in the output.
这个问题实在太简单,要说有什么难的就是小弟的英语水平跟不上打字水平。由于实在太简单,我就不按老规矩分析了,只是指出需要注意的方面并拓展。
- 听江湖传言,WA最多的就是精度问题了。不少同志由于不是用Java,所以精度没控制好。
对于这个问题,下面列出四种java里面的解决方法:
- 最简单的,System.out.println(String.format("%.2f", f));或者System.out,printf("%.2f",a);
- DecimalFormat df = new DecimalFormat("#.00"); System.out.println(df.format(f));
- NumberFormat nf = NumberFormat.getNumberInstance();
- nf.setMaximumFractionDigits(2);
- System.out.println(nf.format(f));
- BigDecimal bg = new BigDecimal(f);
- double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
- System.out.println(f1);
感谢总结上面方法的同志!
版权声明:本文为博主原创文章,未经博主允许不得转载。
Poj_1004_FinancialManagement的更多相关文章
随机推荐
- WiX 中XML引用变量说明
WiX 安装工程中的XML 文件所引用变量说明: The WiX project supports the following project reference variables: Variabl ...
- web前端开发-Ajax(2)
前面的一篇博文简单的简绍了Ajax基于jQuery的用法,接下来要对Ajax做进一步的介绍,Ajax请求大致可以通过三种方式发送:原生Ajax,jQuery,伪Ajax.1.原生Ajax: 由于Aja ...
- PHP的依赖管理工具----composer
安装Composer 参考:https://getcomposer.org/doc/01-basic-usage.md composer 是PHP依赖管理工具 PHP最低版本要求5.3.2,需要允许o ...
- Java并发之BlockingQueue
一.Queue Queue是队列接口是 Collection的子接口.除了基本的 Collection操作外,队列还提供其他的插入.提取和检查操作.每个方法都存在两种形式:一种抛出异常(操作失败时 ...
- Navicat Premium试用期破解方法(转)
转载网址https://blog.csdn.net/Jason_Julie/article/details/82864187 1.按步骤安装Navicat Premium,如果没有可以去官网下载:ht ...
- mapreduce源码解析以及优化
http://blog.csdn.net/wisgood/article/details/8793483 优化 http://blog.csdn.net/wisgood/article/details ...
- Data Structure Binary Tree: Convert a given tree to its Sum Tree
http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...
- 常用grads函数
GrADS的函数分两类, 一类是对格点/站点数据执行运算的,这一类我们姑且称之为分析函数; 另一类是脚本编程(gs)时使用的, 这后一类我们姑且称之为脚本函数. 第一类分析函数又分为格点分析和站点分析 ...
- [原创]java WEB学习笔记34:Session 案例 之 解决表单重复提交
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 第四篇、javascript
一.正则表达式 提示:此专题需要多轮复习反复的加深和理解 正则表达式的两种用法: 1)regexp.xxx(string); 2)string.yyy(regexp); 验证用户输入的手机号格式是否合 ...