保留小数精度
来源:互联网 发布:冲突世界 知乎 编辑:程序博客网 时间:2024/05/17 21:47
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
Sample Input
95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
解决方案
package OJ;import java.math.BigDecimal;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);BigDecimal r = scanner.nextBigDecimal();int n = scanner.nextInt();r = r.pow(n);String result = r.stripTrailingZeros().toPlainString();if (result.startsWith("0.")) {result = result.substring(1);}System.out.println(result);}}
0 0
- 保留小数精度
- 如何保留小数精度
- C / C++中保留小数精度
- jquery 小数计算保持精度,同时保留两位数
- 【高精度算法】A/B 高精度除以低精度 保留小数
- 小数精度
- 小数精度。
- PHP_保留两位小数并且四舍五入(可用于精度计算)_保留两位小数并且不四舍五入,
- 保留小数
- 保留小数
- 保留小数
- c++、vc++ 数据精度、小数点取舍、数据四舍五入、保留2位小数
- c++、vc++ 数据精度、小数点取舍、数据四舍五入、保留2位小数、数据之间加入","
- java基础 double双精度保留两位小数最简单操作
- js限制金额输入框(最高精度为保留6位小数)
- 文本四则运算解析工具与浮点数小数精度保留工具
- 小数按精度转换
- 小数精度设置
- linux命令详解之du命令
- [题解]CodeChef APRIL Challenge 17
- 堆-优先队列
- 最大差值
- 洛谷 P2598 [ZJOI2009]狼和羊的故事
- 保留小数精度
- MapleStory引擎-介绍
- 算法之 KMP匹配算法2
- manacher算法----O(n)最长回文串
- Web基础之Servlet深入
- 从jsp页面中连接数据库并进行相关操作(增删查改)
- Mysql中的where子句
- Room
- [LeetCode]234. Palindrome Linked List