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的更多相关文章
随机推荐
- 关于iOS的手势UIGestureRecognizer问题
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { UIGestureRecognizerStatePossible, // 尚未识别是何种手 ...
- thymeleaf基本应用
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- 矩阵乘法 NOI2012的一道题
今天,kzj大佬教了我矩阵加速. 让我以这篇随笔表示感谢吧! 这是我刷的一道题:NOI2012 随机数据生成器. 就是普通的矩阵加速,只是要注意的是: 直接用乘法会爆long long,可以参考一下 ...
- 梯度下降算法(gradient descent)
简述 梯度下降法又被称为最速下降法(Steepest descend method),其理论基础是梯度的概念.梯度与方向导数的关系为:梯度的方向与取得最大方向导数值的方向一致,而梯度的模就是函数在该点 ...
- php验证复选框的小例子
发布:thatboy 来源:Net [大 中 小] 本文介绍一个简单的php实例,通过代码验证复选框值的有效性,有需要的朋友,可以参考下. 验证复选框的php代码,如下: <?php ...
- [转]Homebrew 卸载时出现:Failed to locate Homebrew! 错误
今天在 MacBook 上安装 Homebrew,结果中间断了网,想重新卸载重装,结果一直卸载失败.问题现象如下: 问题现象 卸载时错误如下: ruby -e "$(curl -fsSL h ...
- 在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途
contex指上下文,实际上就是一个web项目:path是虚拟目录,访问的时候用127.0.0.1:8080/welcom/*.jsp访问网页,welcome前面要加/;docBase是网页实际存放位 ...
- redis于spring整合之RedisTemplate
原文地址: http://www.jianshu.com/p/7bf5dc61ca06
- import from 'xxx'是如何找到node_modules目录下的
起初我认为这是ES6或者Webpack的语法,但查阅相关API后并没有相关说明,通过进一步地搜索,才知道这是Node模块系统的约定和实现(Webpack打包工具是兼容node模块系统的,自然遵守相关规 ...
- web框架详解之tornado 二 cookie
一.tornado之cookie一 目录: <!DOCTYPE html> <html lang="en"> <head> <meta c ...