mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Allows the user to set the precision for their exchange rate values. Config setting: ``` exchangerates: precision: 3 ``` Default is `7`. Also aligns converted values along the decimal place for improved aesthetics. Signed-off-by: Chris Cummer <chriscummer@me.com>
15 lines
379 B
Go
15 lines
379 B
Go
package wtf
|
|
|
|
import "math"
|
|
|
|
// Round rounds a float to an integer
|
|
func Round(num float64) int {
|
|
return int(num + math.Copysign(0.5, num))
|
|
}
|
|
|
|
// TruncateFloat64 truncates the decimal places of a float64 to the specified precision
|
|
func TruncateFloat64(num float64, precision int) float64 {
|
|
output := math.Pow(10, float64(precision))
|
|
return float64(Round(num*output)) / output
|
|
}
|