https://school.programmers.co.kr/learn/courses/30/lessons/120878
function solution(a, b) {
return Number((a / b).toFixed(10)) === a / b ? 1 : 2;
}
toFixed()를 활용해 소수점 아래 10의 자리만큼 표기합니다. 소수점 아래 자리가 10이 넘어갈 경우 무한 소수 확률이 높기 때문에 통과가 가능합니다. 주의 사항으로는 toFixed()를 사용할 경우 문자열로 반환하기 때문에 반드시 Number를 붙여야 합니다.
Yes, you would need to use the Number function in conjunction with the toFixed method when you want to round a decimal number to a specific number of decimal places. The reason for this is that the toFixed method is a method of the Number object and is not available on primitive data types like float or double.
The toFixed method returns a string representation of a number rounded to a specific number of decimal places. By wrapping the number in the Number function, you convert the string representation back into a number so that you can perform further mathematical operations on it.
var number = 3.14159265;
var roundedNumber = Number(number.toFixed(2));
console.log(roundedNumber); // Output: 3.14
In this example, number is a decimal number that we want to round to 2 decimal places. The toFixed method is called on number and the resulting string is converted back into a number using the Number function. The roundedNumber variable now holds the rounded value of the original number.