Original article: http://demon.tw/copy-paste/javascript-precision.html
Precision loss of small numbers and big integers in Javascript
Title: Precision loss of small numbers and big integers in JavascriptAuthor: demonLink:
The following describes the precision of float operations in javascript. Someone asked a js question:
The Code is as follows:
Var I = 0.07;Var r = I * 100;Alert (r );
Why is the result 7.0000000000000001?
After checking the information, we know
This article is mainly to share with you PHP to achieve high-precision computing, engaged in the financial industry, capital operations frequently, here I met the pit .... Slightly inattentive, the user funds may lose hundreds of thousands of, even
In javascript, regardless of Single-precision float and double-precision, all decimal variables are regarded as float. Therefore, to obtain the n digits after decimal places, use the toFixed (n) method to obtain
Convert js numbers to float and take
Someone asked a js question:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->var i = 0.07;var r = i*100;alert(r);
Why is the result 7.0000000000000001?
After checking the information, we know that
Someone asked a js question:Copy codeThe Code is as follows:Var I = 0.07;Var r = I * 100;Alert (r ); Why is the result 7.0000000000000001?After checking the information, we know that in JavsScript, variables are stored by float instead of the number
Someone asked a JS question:
Copy Code code as follows:
var i = 0.07;
var r = i*100;
Alert (R);
The result is 7.0000000000000001?
Check the data, in fact, we know that in Javsscript, variables are stored without
In JavaScript, no single precision float and double doubles, all the decimal variables are considered float, so to take the decimal number of n, to use the method tofixed (n) to getJS number converted to float, take n decimal: =======================
We often see some data types in javascript, such as "undefined", "boolean", and "string, this article will help you learn the basic JavaScript data types, value types, and reference types. For more information, see this article, four basic data
The variables in JavaScript are weak types, all variables are declared as Var, and in the process of type conversion is not as convenient as Java, it is through parseint (variable), parsefloat (variable) and other methods to do type conversion. Note:
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.