mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Add float rounding function.
This commit is contained in:
21
common.go
21
common.go
@@ -6,8 +6,29 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"errors"
|
||||
"math"
|
||||
)
|
||||
|
||||
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 -= 1
|
||||
}
|
||||
if frac >= x {
|
||||
rounder = math.Ceil(intermed)
|
||||
} else {
|
||||
rounder = math.Floor(intermed)
|
||||
}
|
||||
|
||||
return rounder / pow
|
||||
}
|
||||
|
||||
func CalculateAmountWithFee(amount, fee float64) (float64) {
|
||||
return amount + CalculateFee(amount, fee)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user