In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "JavaScript area does not distinguish between integers and floating point numbers", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript area does not distinguish between integers and floating point numbers" article.
JavaScript does not distinguish between integer values and floating-point values. All numbers in JavaScript are stored as 64-bit floating-point numbers, including integers, for example, 2 and 2 are the same number; so pay special attention to the lack of schedule when performing numeric operations.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Number digital representation method
Number types represent numbers, and JavaScript uses the double precision 64-bit format defined by the IEEE 754 standard ("double-precision 64-bit format IEEE 754 values") to represent numbers.
Unlike other programming languages (such as C and Java), JavaScript does not distinguish between integer and floating-point values, and all numbers are represented by floating-point values in JavaScript, so pay special attention to the lack of schedule when performing numeric operations.
0.1 + 0.2 = 0.30000000000000004 equal var ACCURACY / false// floating-point operation determines equality var ACCURACY = 1eMube 5; / / the definition accuracy is as accurate as 0.00001var a = 0.1bot var b = 0.2bot var sum = 0.3ram / the difference is considered to be equal if if the difference is less than the precision {console.log ('aqb = sum');}
In an implementation, integer values are usually treated as 32-bit integer variables and are also stored as 32-bit integer variables in individual implementations, such as some browsers, until they are used to perform operations that 32-bit integers do not support. This is to facilitate bit operations.
You can use an omission of 0 to represent a decimal, or you can represent a number exponentially
.9; / / 910 / / 10002e6 / / 20000000.1e2 / / 101e-5 / / 0.00001Number representation of different digits with different digits
Number can use four numeric bases: decimal, binary, octal and hexadecimal. Non-decimal is used only with integers.
Binary representation: begins with zero, followed by a lowercase or uppercase Latin letter B (0b or 0B)
Octal representation: beginning with 0. If the number after 0 is not in the range of 0 to 7, the number will be converted to a decimal number.
Octal syntax is prohibited in ECMAScript 5 strict mode and will be considered decimal
Using octal numbers in ECMAScript 6 requires adding the prefix "0o" to a number
Hexadecimal representation: begins with zero, followed by a lowercase or uppercase Latin letter X (0x or 0X)
/ / Decimal 12345678420777 / / will be treated as octal in non-strict format (511 in decimal) / / binary var a = 0b100000; / / 32var b = 0b0111111; / / 63var c = 0B0000111; / / 7jump / octal var n = 0755; / / 493var m = 0644; / / 420var a = 0o10 / / ES6: Octal / / hexadecimal 0xFFFFFFFFFFFFFFFFF / / 2951479051793528300000x123456789ABCDEF / / 819855292164869000XA / / 10 conversion of different binary
The binary conversion mainly uses the toString () method or parseInt () method of Number:
The toString () method accepts an integer argument between 2 and 36, which defaults to decimal, and converts Number to String.
The second parameter of parseInt () accepts an integer argument with a value between 2 and 36, which defaults to decimal, converting String to Number
/ / toString conversion, input as Number, returned as Stringvar n = 120 "n.toString (2); / /" 1111000 "n.toString (8); / /" 170" n.toString (16); / / "78" n.toString (20); / / "60" 0x11.toString (); / / "17" 0b111.toString (); / / "7" 0x11.toString (12) / / "15" / / parseInt conversion, input as String, return as NumberparseInt ('110binary, 2); / 110parseInt (' 110binary, 2); / / 6parseInt ('110binary, 8); / / 72parseInt (' 110binary, 16); / / 272parseInt ('110binary, 26); / / 702 toString / parseInt can be used in combination with parseInt to convert a from 36 to 12 var a =' ra' The number parseInt (a, 36) .toString (12); / / "960" digital object Number
The Number object is a built-in digital object that encapsulates a series of Number-related constants and methods.
Var na = Number (8); / 8na = Number ('9.5'); / / 9.5na = new Number (' 9.3'); / / Number object, you can only use the prototype method Number object property: the property describes the maximum value that can be represented by Number.MAX_VALUE, the minimum value that Number.MIN_VALUE can represent, Number.NaN refers to "non-numeric" Number.NEGATIVE_INFINITY refers to "negative infinity", and returns Number.POSITIVE_INFINITY specifically "positive infinity" in case of overflow Returns the difference between Number.EPSILON representing 1 and the minimum Number with a ratio of 1 and greater than 1 in case of overflow Number.MIN_SAFE_INTEGERJavaScript minimum safe integer Number.MAX_SAFE_INTEGERJavaScript maximum safe integer Number object method
The Number object method can use Number. You can also use a global call.
Method description Number.parseFloat () parses string parameters into floating-point numbers, which is equivalent to unary operation algorithm + Number.parseInt () parsing strings into integer digits corresponding to a specific cardinality Number.isFinite () to determine whether the passed value is a finite number Number.isInteger (), to determine whether the passed value is an integer Number.isNaN (), to determine whether the passed value is NaNNumber.isSafeInteger (), to determine whether the passed value is a safe integer.
The parseInt () method needs to be noted:
The parseInt () parameter can have two parameters: a numeric string and a binary
If the first parameter is a non-specified numeric string, the result is 0
If the first parameter is a non-string, the toString () method of the parameter is first called to convert it to a string
Non-specified base recognizable characters in the first parameter are ignored
If a given string does not have a numeric form, the function returns a special value NaN
If the second argument is not provided when called, the base of the number represented by the string is used
ParseInt ('123'); / 123parseInt (' 123lines, 10); / / 123parseInt ('123parameters, 8); / / 83parseInt (' 123parameters, 16); / / 291parseInt ("11", 2); / / 3parseInt ('0x123arguments, 10); / / 0parseInt (' 0x123arguments, 16); / / 291parseInt ('0x123'); / / 291impulse / if the first parameter is not a string, the first parameter is first converted to the string parseInt (' 123arguments, 16). / / 18parseInt (12, 16); / 18 NaNparseInt / toString method converts numbers to decimal string parseInt (0xf, 16); / / 210xf.toString (); / / '15'parseInt (' 15, 16); / / 21parseInt ('23.56'); / / 23parseInt ("hello", 16); / / NaNparseInt ("aello", 16); / / 174Number type prototype method
There are also methods on the Number type prototype to make trade-offs about digital progress, which can be called by the Number instance object:
The method description toExponential () returns the string toFixed () in exponential form of a number. The representation of the specified number of decimal places, toPrecision (), returns a number of specified precision.
These prototype methods can be called by the Number instance object:
Var numObj = 12345.6789 num Obj.toExponential (); / / "1.23456789e+4" numObj.toExponential (2); / / "1.23e+4" numObj.toExponential (4); / / "1.2346e+4" numObj.toPrecision (); / / "12345.6789" numObj.toPrecision (2); / / "1.2e+4" numObj.toPrecision (4); / / "1.235e+4" numObj.toFixed () / / return "12346": round off, excluding fractional numObj.toFixed (1); / / return "12345.7": round numObj.toFixed (6); / / return "12345.678900": fill (1.23e+20) .tofixed (2) with 0; / / return "123000000000000000000.00" (1.23e-10) .tofixed (2) / / returns "0.00" 2.34.toFixed (1); / / returns "2.3"-2.34.toFixed (1); / / returns-2.3 (negative numbers do not return a string due to operator priority) (- 2.34) .tofixed (1) / / returns "- 2.3" (string is returned if priority is raised with parentheses) Mathematical object (Math)
Related to Number, the Math object built into the JavaScript object provides a lot of properties and methods for mathematical constants and functions.
List of attributes:
The attribute describes the Math.E Euler constant, which is also the base of the natural logarithm, which is approximately equal to the natural logarithm of 2.718Math.LN22, the natural logarithm of 0.693Math.LN1010, the logarithm of 2.303Math.LOG2E with base 2 as E, the logarithm of 1.443Math.LOG10E with base 10 as E, the ratio of circumference to diameter of a circle. Approximately equal to the square root of 3.14159Math.SQRT22, approximately equal to the square root of 1.414Math.SQRT1_21/2, about 0.707
Trigonometric function sin and other parameters in Math are radians. If it is an angle, you can use it (Math.PI / 180)
Method describes the absolute value of x returned by Math.abs (x) Math.sign (x) returns the symbolic function of x and determines that x is a positive number Negative or 0Math.random () returns pseudorandom numbers between 0 and 1 Math.floor (x) returns the value of x rounded up Math.ceil (x) returns the value of x rounded up Math.round (x) returns the rounded integer. Math.fround (x) returns the nearest single-precision floating-point representation of the number Math.trunc (x) returns the integer part of x Remove the decimal Math.sqrt (x) return the square root of x Math.cbrt (x) return the cube root of x Math.hypot ([x [, y [, …]) Returns the square root of the sum of the squares of its parameters Math.pow (x) returns the y power of x min (), max () returns a smaller or larger value (respectively) sin (), cos (), tan () standard trigonometric function in the numerical parameter list separated by commas; the parameters are Radian asin (), acos (), atan (), atan2 () inverse trigonometric function; the return value is Radian sinh (), cosh (), tanh () hyperbolic trigonometric function The return value is Radian .asinh (), acosh (), atanh () inverse hyperbolic trigonometric function. The return value is Radian .pow (), exp (), expm1 (), log10 (), log1p (), log2 () Index and logarithmic function. The above is about "JavaScript area does not distinguish between integers and floating point numbers". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.