[javascript] 숫자 반올림, 올림, 내림steemCreated with Sketch.

in hive-137029 •  2 years ago 

숫자 반올림, 올림, 내림

Math 함수 사용

  • Math.floor()
    • 소수점 이하를 버림
  • Math.ceil()
    • 소수점 이하를 올림
  • Math.round()
    • 소수점 이하를 반올림

소수점 n번째 자리 반올림

  • Math 함수 사용

    • const pie = 3.14159265358979;
      Math.round(pie*100)/100.0
      
  • toFixed() - 원하는 소수점 길이만큼 반올림하여 변환

    • const pie = 3.14159265358979;
      pie.toFixed(2)
      
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

image.png

Upvoted! Thank you for supporting witness @jswit.