Home >Web Front-end >JS Tutorial >A brief analysis of floating point arithmetic problems in js_javascript skills

A brief analysis of floating point arithmetic problems in js_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:05:181035browse

How are floating point operations performed in js?

For example: var a=0.69;

I want to get 6.9 by writing var c=a*10;

alert(c); The result is: 6.8999999999999995

After searching online, some netizens said that this is a JS floating point calculation bug and found a solution:

Method 1: Have js custom function

Copy code Code As follows: