diff --git a/internal/common/service/common.hpp.service.go b/internal/common/service/common.hpp.service.go index 1b94e791..44f2dd5f 100644 --- a/internal/common/service/common.hpp.service.go +++ b/internal/common/service/common.hpp.service.go @@ -2,6 +2,7 @@ package service import ( "context" + "math" "time" commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository" @@ -238,10 +239,10 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p Butir: estimPieces, } if estimWeightKg > 0 { - estimation.HargaKg = totalProductionCost / estimWeightKg + estimation.HargaKg = roundToTwoDecimals(totalProductionCost / estimWeightKg) } if estimPieces > 0 { - estimation.HargaButir = totalProductionCost / estimPieces + estimation.HargaButir = roundToTwoDecimals(totalProductionCost / estimPieces) } real := HppCostDetail{ @@ -250,10 +251,10 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p Butir: realPieces, } if realWeightKg > 0 { - real.HargaKg = totalProductionCost / realWeightKg + real.HargaKg = roundToTwoDecimals(totalProductionCost / realWeightKg) } if realPieces > 0 { - real.HargaButir = totalProductionCost / realPieces + real.HargaButir = roundToTwoDecimals(totalProductionCost / realPieces) } return &HppCostResponse{ @@ -261,3 +262,7 @@ func (s *hppService) GetHppEstimationDanRealisasi(totalProductionCost float64, p Real: real, }, nil } + +func roundToTwoDecimals(value float64) float64 { + return math.Round(value*100) / 100 +}