better zero amount checking
This commit is contained in:
		
							parent
							
								
									cf194e6b60
								
							
						
					
					
						commit
						7db9c4c910
					
				| @ -60,12 +60,17 @@ showAmountRounded (Amount c q p) = | |||||||
|     (symbol c) ++ ({-punctuatethousands $ -}printf ("%."++show p++"f") q) |     (symbol c) ++ ({-punctuatethousands $ -}printf ("%."++show p++"f") q) | ||||||
| 
 | 
 | ||||||
| showAmountRoundedOrZero :: Amount -> String | showAmountRoundedOrZero :: Amount -> String | ||||||
| showAmountRoundedOrZero a@(Amount c _ _) = | showAmountRoundedOrZero a | ||||||
|     let s = showAmountRounded a |     | isZeroAmount a = "0" | ||||||
|         noncurrency = drop (length $ symbol c) |     | otherwise = showAmountRounded a | ||||||
|         nonnulls = filter (flip notElem "-+,.0") | 
 | ||||||
|         iszero = (nonnulls $ noncurrency s) == "" | -- | is this amount zero, when displayed with its given precision ? | ||||||
|     in if iszero then "0" else s | isZeroAmount :: Amount -> Bool | ||||||
|  | isZeroAmount a@(Amount c _ _) = nonzerodigits == "" | ||||||
|  |     where | ||||||
|  |       nonzerodigits = filter (flip notElem "-+,.0") quantitystr | ||||||
|  |       quantitystr = withoutcurrency $ showAmountRounded a | ||||||
|  |       withoutcurrency = drop (length $ symbol c) | ||||||
| 
 | 
 | ||||||
| punctuatethousands :: String -> String | punctuatethousands :: String -> String | ||||||
| punctuatethousands s = | punctuatethousands s = | ||||||
|  | |||||||
| @ -37,9 +37,8 @@ showEntryDescription e = (showDate $ edate e) ++ " " ++ (showDescription $ edesc | |||||||
| showDate d = printf "%-10s" d | showDate d = printf "%-10s" d | ||||||
| showDescription s = printf "%-20s" (elideRight 20 s) | showDescription s = printf "%-20s" (elideRight 20 s) | ||||||
| 
 | 
 | ||||||
| -- | quick & dirty: checks entry's 0 balance only to 8 places |  | ||||||
| isEntryBalanced :: Entry -> Bool | isEntryBalanced :: Entry -> Bool | ||||||
| isEntryBalanced = ((0::Double)==) . read . printf "%0.8f" . quantity . sumLedgerTransactions . etransactions | isEntryBalanced = isZeroAmount . sumLedgerTransactions . etransactions | ||||||
| 
 | 
 | ||||||
| autofillEntry :: Entry -> Entry | autofillEntry :: Entry -> Entry | ||||||
| autofillEntry e@(Entry _ _ _ _ _ ts _) = | autofillEntry e@(Entry _ _ _ _ _ ts _) = | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user