mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 14:18:03 -05:00
23 lines
596 B
Go
23 lines
596 B
Go
// Copyright 2023 The AthanorLabs/atomic-swap Authors
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
package coins
|
|
|
|
import (
|
|
"github.com/cockroachdb/apd/v3"
|
|
)
|
|
|
|
func roundToDecimalPlace(result *apd.Decimal, n *apd.Decimal, decimalPlace uint8) error {
|
|
result.Set(n) // already optimizes result == n
|
|
|
|
// Adjust the exponent to the rounding place, round, then adjust the exponent back
|
|
increaseExponent(result, decimalPlace)
|
|
_, err := decimalCtx.RoundToIntegralValue(result, result)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
decreaseExponent(result, decimalPlace)
|
|
_, _ = result.Reduce(result)
|
|
return nil
|
|
}
|