룰렛 합계 검증

- Float를 Decimal로 변경한 후 검증하도록 수정
This commit is contained in:
Klaus 2024-07-02 19:20:00 +09:00
parent 27fbfd49e2
commit 263ca3ac9a
1 changed files with 3 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import kr.co.vividnext.sodalive.member.MemberRole
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.math.BigDecimal
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write
import kotlin.random.Random
@ -236,8 +237,8 @@ class RouletteService(
throw SodaException("룰렛 옵션은 최소 2개, 최대 10개까지 설정할 수 있습니다.")
}
val totalPercentage = items.map { it.percentage }.sum()
if (totalPercentage != 100f) {
val totalPercentage = items.map { BigDecimal(it.percentage.toDouble()) }.reduce(BigDecimal::plus)
if (totalPercentage != BigDecimal(100.0)) {
throw SodaException("확률이 100%가 아닙니다")
}
}