diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 269d4488a..d06c2faa8 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -66,6 +66,7 @@ module Hledger.Data.Amount ( -- ** rendering amountstyle, styleAmount, + styleAmountExceptPrecision, showAmount, cshowAmount, showAmountWithZeroCommodity, @@ -368,6 +369,13 @@ styleAmount styles a = Just s -> a{astyle=s} Nothing -> a +-- | Like styleAmount, but keep the number of decimal places unchanged. +styleAmountExceptPrecision :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount +styleAmountExceptPrecision styles a@Amount{astyle=AmountStyle{asprecision=origp}} = + case M.lookup (acommodity a) styles of + Just s -> a{astyle=s{asprecision=origp}} + Nothing -> a + -- | Get the string representation of an amount, based on its -- commodity's display settings. String representations equivalent to -- zero are converted to just \"0\". The special "missing" amount is