콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1994 화면

I have been learning JavaScript in odd and made this function in POS. It works great, but I want to set the decimal precision to the result number so it only has two decimals.

I've searched a lot and tried different things but none worked for me.

I hope someone have an answer for this.

Example: 

1 / 3 = ‭0.3333333333333333‬    I want the result to be only    0.33

2 / 3 = ‭0.6666666666666667‬     I want the result to be only    0.67

This is the code:

test: function()( 

if (this. bigger){return(this. quantity*3)}

if (this. smaller){return(this. quantity/3)}

return this.  quantity

아바타
취소
작성자 베스트 답변

I was able to set the decimal precision by using tofixed(2)
the correct code would be like this

test: function()( 

if (this. bigger){return(this. quantity*3). tofixed(2) }

if (this. smaller){return(this. quantity/3). tofixed(2) }

return this.  quantity


아바타
취소