Bug fix in RoundFloat func in common/math package (#579)

* refactored RoundFloat func in common/math package

* cleanup

Co-authored-by: Vazha Bezhanishvili <vazha.bezhanishvili@elegro.eu>
This commit is contained in:
Vazha
2020-10-16 02:13:10 +03:00
committed by GitHub
parent 8c86aac21d
commit 9945216cac
3 changed files with 32 additions and 25 deletions

View File

@@ -31,21 +31,6 @@ func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64 {
// RoundFloat rounds your floating point number to the desired decimal place
func RoundFloat(x float64, prec int) float64 {
var rounder float64
pow := math.Pow(10, float64(prec))
intermed := x * pow
_, frac := math.Modf(intermed)
intermed += .5
x = .5
if frac < 0.0 {
x = -.5
intermed--
}
if frac >= x {
rounder = math.Ceil(intermed)
} else {
rounder = math.Floor(intermed)
}
return rounder / pow
return math.Round(x*pow) / pow
}