백준으로 스위프트에 대해 공부하고 있는데, 이상하게 에러가 나타난 문제가 있었다.
문제의 원인은 Float와 Double에 차이로 인해 발생했던 것이다.
처음엔 아무 생각 없이 Float를 사용했는데, 자꾸 틀렸다고 떴다,,,
Float
Double
Swift Docs
Double has a precision of at least 15 decimal digits, whereas the precision of Float can be as little as 6 decimal digits. The appropriate floating-point type to use depends on the nature and range of values you need to work with in your code. In situations where either type would be appropriate, Double is preferred.
Docs를 보면 두 자료형 모두 사용이 가능할 때는 Double 자료형이 선호된다고 하였다.
스위프트는 매우 엄격한 언어이기 때문에 자료형을 잘 생각해야겠다.
또한 꼭 Float를 사용해야하는 경우가 아니면 Double을 사용하도록 하자.
Double로 변경해주니 되었다.
let input = readLine()! //input 받기
let arr = input.split(separator: " ")
let A = Double(arr[0])!
let B = Double(arr[1])!
print(A / B)