JS uses parseFloat to cause precision problems

One of the bugs submitted by the page test: the
area value in the floating box does not display abnormally Insert picture description here
. The code for data processing at the front desk: loop to find the data item and then count

				count = json[DEFECT_CNAME[X]][j][2];
				count+=parseFloat(list[i].DEFECT_AREA);
				json[DEFECT_CNAME[X]][j][2]=count;

The test found that...this calculation will indeed cause abnormal accuracy. The Insert picture description here
solution is as follows:

count = json[DEFECT_CNAME[X]][j][2];
count=Math.floor((parseFloat(list[i].DEFECT_AREA+count))*100)/100;
json[DEFECT_CNAME[X]][j][2]=count;

Test passed:
Insert picture description here

Guess you like

Origin blog.csdn.net/Beatingworldline/article/details/113699114