JavaScript Quiz
Explain the output of the following code.
console.log(0.1 + 0.2); //0.30000000000000004 console.log(0.1 + 0.2 == 0.3); //false
JavaScript is in floating-point number type, JavaScript, IEEE-754 floating-point using a predetermined format, which is a binary representation can be accurately represent fraction, such as 1 / 2,1 / 8,1 / 1024, each float accounting for 64. However, binary floating point representation does not accurately represented by simple numbers such 0.1 Similarly, there will be rounding error.
The binary, JavaScript can not limited represents 1 / 10,1 / 2 and the like this fraction. In binary, 1/10 (0.1) is expressed as .00110011001100110011 ...... note 0011 is infinitely repeated, which is caused by rounding errors, so 0.1 + 0.2 for such operations, the operands will first be converted to binary, and then recalculation:
0.1 => 100110011001 ... 0.0001 (infinite loop)
0.2 => 001100110011 ... 0.0011 (infinite loop)Fractional part of double precision floating point support up to 52, so the two get so 0.0100110011001100110011001100110011001100 ... a bunch of binary digits due to the limitations of floating-point decimal places and truncated after the addition, at this time, then convert it to decimal, you It became .30000000000000004.
MySQL programming problems
Table name student_score
name | course | score |
---|---|---|
Joe Smith | Chinese | 81 |
Joe Smith | mathematics | 75 |
John Doe | Chinese | 76 |
John Doe | mathematics | 90 |
Wang Wu | Chinese | 81 |
Wang Wu | mathematics | 100 |
Wang Wu | English | 90 |
Check out student information is greater than the average score of 75 points, "Zhang" surnamed students.
SELECT * FROM student_score WHERE name IN (SELECT name FROM student_score WHERE name LIKE '张%' GROUP BY name HAVING AVG(score) > 75)
Java programming problem
Monkey eating peach issues: the monkey off his first day of a number of peach, half eaten immediately, not addiction, but also to eat the next morning a turn eaten by the remaining peach half, then eat one. After the morning before the rest of the day eat half a zero. When the morning of the 10th day want to eat, see only one peach. Seeking first day were picked number.
Package Test; / ** * Analysis procedure: The method of reverse thinking taken from the forward inference * @author the CUI * / public class TL6 { public static void main (String [] args) { int NUM =. 1 ; for ( int . 1 = I; I <=. 9; I ++ ) { NUM = (+ NUM. 1) * 2 ; } System.out.println ( "the first day were picked" + num + "peach" ); } }