Math.round() Math.ceil() Math.floor() diff

Math.round() round literally means "nearby around" 

The first digit after the decimal point <5

Positive number: Math.round(11.46)=11

Negative numbers: Math.round(-11.46)=-11

 

The first digit after the decimal point>5

Positive number: Math.round(11.68)=12

Negative numbers: Math.round(-11.68)=-12

 

The first digit after the decimal point=5

Positive number: Math.round(11.5)=12

Negative numbers: Math.round(-11.5)=-11

Summary: Rounding up

2. Math.ceil(): According to the literal meaning of "ceil" "ceil" to understand;

For example:

Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=12

Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-11

Summary: round up

3.Math.floor(): understand according to the literal meaning of "floor";

For example:

Math.floor(11.46)=Math.floor(11.68)=Math.floor(11.5)=11

Math.floor(-11.46)=Math.floor(-11.68)=Math.floor(-11.5)=-12

Summary: round down

おすすめ

転載: blog.csdn.net/guoweifeng0012/article/details/95340749