Chapter 2 Precise Calculation of Java floating point numbers and Chapter 2 java floating point numbers
1. Practical Significance
In actual development, if precise float or double computing (especially financial computing) is required ), directly
public class Arith {/** * because Java's simple type does not accurately calculate floating-point numbers, this tool class provides precise floating-point arithmetic, including subtraction and rounding. *///Default division operation precision
Copy codeThe Code is as follows: // Note: The javascript addition result has an error, which is obvious when the two floating point numbers are added. This function returns a more accurate addition result.// Call: accAdd (arg1, arg2)// Return value:
Package com.minxinloan.utils;Import Java.math.BigDecimal;public class Arith {Source file Arith.java:/*** Because Java's simple type does not accurately operate on floating-point numbers, this tool class provides accurate floating-point arithmetic,
BC is the abbreviation for binary calculator. The arguments to the bc* function are the operands plus an optional [int scale], such as String Bcadd (String $left _operand, String $right _operand[, int $scale]), if scale is not provided , the default
Question:What do we see if we compile and run the following program?Public class Test {Public static void main (String args []) {System. out. println (0.05 + 0.01 );System. out. println (1.0-0.42 );System. out. println (4.015*100 );System. out.
Question: Give a finite decimal or an infinite repeating decimal number, and use the smallest denominator to accurately express this number with a fraction. Parentheses indicate the cyclic part, for example:
0.3, 0.3 (3), 0.3 (0)
Thought: I saw it,
Precise Timing based on windows in VCYouzhiyu, Institute of optoelectronic technology, Chinese Emy of SciencesDownload Sample projectIn the industrial production control system, there are many operations that require timed completion, such as
This article introduces you to precise calculation, numerical formatting, and direct introduction of js files.
The Code is as follows:
(Function (){Var calc = {/*The addition function is used to obtain accurate addition results.Note: The addition
BC is short for Binary calculator. BC * function parameters are all operands plus an optional [int scale], such as string bcadd (string $ left_operand, string $ right_operand [, int $ scale]). If scale is not provided, use the default value of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.