decimal3 Python _ Decimal 모듈로 부동 소수점 문제 해결하기 Decimal 이란? Decimal은 '부동 소수점 문제'를 해결하고 소수점을 정확하게 표현하기 위해 사용하는 Python 자료형이다. 컴퓨터에서는 소수를 이진수로 표현하다 보니, 0.1과 같은 값이 정확하게 표현되지 않을 수 있다. 이러한 문제 때문에 금융, 회계 등 정확한 계산이 필요한 경우에는 Decimal을 사용해야 한다. 예를 들어, 파이썬에서 소수형을 그대로 사용하면 다음과 같은 부동 소수점 문제가 발생할 수 있다. value = 0.1 + 0.2 print(value) # 출력: 0.30000000000000004 하지만 아래처럼 Decimal 모듈을 사용하면 이런 문제를 피할 수 있다. from decimal import Decimal value = Decimal('0.1') + Decim.. 2023. 5. 16. Get the mean of an array Description: It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the given array rounded down to its nearest integer. The array will never be empty. Solution: 1. Find the average. 2. Rounds down to an inte.. 2022. 4. 15. Growth of a Population Description: In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants? At the end of the first year there will be: 1000 + 1000 * 0.02 + 50 => 1070 inhabitants At .. 2022. 3. 1. 이전 1 다음