mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user