//*************************************//
// Create a label by defining the Method
//*************************************//
VaR createlabel = function (ID, name, value ){
VaR label_var = Document. createelement ("label ");
VaR
The problem is as follows:37.5*5.5 = 206.08 (JS calculates this result. I rounded it to two decimal places)I first suspected it was a rounding problem, and I used js to calculate a result: 206.08499999999998.How can this happen? How can we multiply
Js floating-point operations and js floating-point operations
Problem Introduction: today, when processing the phase multiplication of two numbers in front-end js, there is a precision deviation: 1.2*3 = 3.9999999995, which should have been 3.6.
In Javascript There are several ways to make a string as a section of the JS code to execute:
Use eval (" string to execute ")
Use the new Function (" string to execute ")
SetTimeOut (" string to execute ", +)
Ajax passes parameters to Xmlhttpreq.onreadystatechange
Pass:
xmlhttp.onreadystatechange= function () {XX (123)};
Or xmlhttp.onreadystatechange= the new Function ("XX (123)"); It's OK.
Copy Code code as follows:
Ajax passes
This article has sorted out some JS common custom public functions such as checking whether the date format, judging whether the characters entered are Chinese, judging whether it is empty, fixed telephone, mobile phone number and so on The
Once the project used to find this code on the Internet before, but under certain conditions Division and addition operations will still appear bugs individual to this slightly optimized
Copy Code code as follows:
The Division
JS small number of multiplication operations will appear floating-point errors, you can test the specific:
The result is 251.89999999999998, not 251.9.
There must be a lot of people who have a headache for this problem. So how to solve it? A
Define method to create a label label
//*************************************//
Copy Code code as follows:
var Createlabel = function (ID, name, value) {
var Label_var = document.createelement ("label");
var label_id =
JS floating-point data type calculation, the following example:
Description: JavaScript multiplication results will be error, in two floating-point numbers are more obvious when multiplying. This function returns a more accurate result of the
First, with JS calculation
12.32 * 7 How much is the result? Answer: 86.24000000000001
Why is there such a problem? How to solve?JS in processing decimal multiplication and division of the time there is a bug, the solution can be: The decimal into
Front.
Error handling is critical for Web application development, not anticipating possible errors in advance, not taking a recovery strategy in advance, and potentially leading to a poor user experience. Because any JavaScript error can cause a
First, with JS calculation
12.32 * 7 How much is the result?Answer: 86.24000000000001Why is there such a problem? How to solve?JS in processing decimal multiplication and division of the time there is a bug, the solution can be: The decimal into an
First, with JS calculation12.32 * 7 How much is the result? Answer: 86.24000000000001
Why is there such a problem? How to solve?JS in processing decimal multiplication and division of the time there is a bug, the solution can be: The decimal into
Copy Code code as follows:
String.prototype.trim = function () {
Return This.replace (/(^\s*) | ( \s*$)/g, "");
}
Check to see if it's a date format
function IsDate (DATESTR) {
var result = Datestr.match (/(^ (1[8-9]\d{2}) | ( [2-9]\d{3}
Main introduction: JavaScript reinforcement tutorial-javascript from simplified to complex JavaScript reinforcement tutorial-from simple to complex
JS, no compilation required. The interpreter is part of the JavaScript engine-browser. Dynamic type,
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.