首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JS-数目字类型

2013-03-25 
JS-数字类型?Because of rounding error, the difference between the approximations of .3 and .2 is no

JS-数字类型

?Because of rounding error, the difference between the approximations of .3 and .2 is not exactly the same as the difference between the approximations of .2 and .1.It is important to understand that this problem is not specific to JavaScript:it affects any programming languages that uses binary floating-point numbers.

A future version of JavaScript may support a decimal numeric type that avoids these rounding issues.Until then you might want to perform critical financial calculations using scaled integers.For example, you might manipulate monetary values as integer cents rather than fractional dollars.

?

?Arithmetic:Javascript programs work with numbers using the arithmetic operators.In addition to these basic arithmetic operators, it supports more complex mathematical operations through a set of functions and constants defined as properties of Math object.For example:

JS-数目字类型

Arithmetic in JavaScript doen not raise errors in cases of overflow, underflow, or division by zero.

    "negative zero" is almost completely indistinguishable from regular zero and JavaScript programmers rarely need to detect it.Division by zero is not an error in JS:it simply returns infinity or negative infinity.there is one exception, however:zero divided by zero does not hava a well-defined value,the result of this operation is the special not-a-number value, printed as NaN.?
Number.POSITIVE_INFINITYNumber.MAX_VALUENumber.NaNNumber.NEGATIVE_INFINITYNumber.MIN_VALUE//Infinity,-Infinity,NaN//console.log(isNaN(111))console.log(isNaN(NaN))console.log(isFinite(Number.POSITIVE_INFINITY))console.log(Number.POSITIVE_INFINITY == Infinity)
?ECMAScript3,Infinity and NaN are read/write values and can be changed.ECMAScript5 corrects this and makes the values read-only.The Number object defines alternatives that are read-only even in ECMAScript3.?

?

?

热点排行