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的更多相关文章
随机推荐
- 函数的光滑化或正则化 卷积 应用 两个统计独立变量X与Y的和的概率密度函数是X与Y的概率密度函数的卷积
http://graphics.stanford.edu/courses/cs178/applets/convolution.html Convolution is an operation on t ...
- CentOS6下安装PHP7
更新软件源[1] wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm wget http://rpm ...
- Unity 武器拖尾效果
Pocket RPG Weapon Trails 武器拖尾效果 Asset Store地址:https://www.assetstore.unity3d.com/en/#!/content/2458 ...
- linux c编程:进程控制(二)_竞争条件
前面介绍了父子进程,如果当多个进程企图对共享数据进行处理.而最后的结果又取决于进程运行的顺序时,就认为发生了竞争关系.通过下面的例子来看下 在这里标准输出被设置为不带缓冲的,于是父子进程每输出一个字符 ...
- android启动页延时跳转
package com.goodness.goodness; import android.content.Context; import android.content.Intent; import ...
- onclick事件表示方法
onclick事件表示方法 1.第一种是直接在html中插入onclick事件 & ...
- vim python缩进等一些配置
VIM python下的一些关于缩进的设置: 第一步: 打开终端,在终端上输入vim ~/.vimrc,回车. 第二步: 添加下面的文段: set filetype=python au BufN ...
- pinpoint改造支持查询
原架构 改造后架构
- oracle字符串函数总结
字符函数——返回字符值 这些函数全都接收的是字符族类型的参数(CHR 除外)并且返回字符值.除了特别说明的之外,这些函数大部分 返回VARCHAR2类型的数值.字符函数的返回类型所受的限制和基本数据库 ...
- 一步一步带你分析 requirejs
详细源代码一共就2000多行,来看我这篇分析的同学应该都下载下来了,好了,话不多说,开始: 代码的开头就出现3个全局变量: requirejs, require, define var require ...