lib: setNaturalPrecisionUpTo
This commit is contained in:
parent
5cb334514c
commit
2da50875ee
@ -77,6 +77,7 @@ module Hledger.Data.Amount (
|
||||
withPrecision,
|
||||
setFullPrecision,
|
||||
setNaturalPrecision,
|
||||
setNaturalPrecisionUpTo,
|
||||
setAmountInternalPrecision,
|
||||
withInternalPrecision,
|
||||
setAmountDecimalPoint,
|
||||
@ -298,6 +299,14 @@ setNaturalPrecision a = setAmountPrecision normalprecision a
|
||||
where
|
||||
normalprecision = fromIntegral $ decimalPlaces $ normalizeDecimal $ aquantity a
|
||||
|
||||
-- | Set an amount's display precision to just enough so that all
|
||||
-- significant decimal digits will be shown, but not more than the
|
||||
-- given maximum number of decimal digits.
|
||||
setNaturalPrecisionUpTo :: Int -> Amount -> Amount
|
||||
setNaturalPrecisionUpTo n a = setAmountPrecision (min n normalprecision) a
|
||||
where
|
||||
normalprecision = fromIntegral $ decimalPlaces $ normalizeDecimal $ aquantity a
|
||||
|
||||
-- | Get a string representation of an amount for debugging,
|
||||
-- appropriate to the current debug level. 9 shows maximum detail.
|
||||
showAmountDebug :: Amount -> String
|
||||
|
||||
Loading…
Reference in New Issue
Block a user