show numbers with thousands separator
This commit is contained in:
		
							parent
							
								
									0445086286
								
							
						
					
					
						commit
						a266a9b2e0
					
				
							
								
								
									
										12
									
								
								Amount.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Amount.hs
									
									
									
									
									
								
							| @ -50,12 +50,22 @@ parseAmount s = nullamt | |||||||
| 
 | 
 | ||||||
| showAmountRoundedOrZero :: Amount -> String | showAmountRoundedOrZero :: Amount -> String | ||||||
| showAmountRoundedOrZero (Amount cur qty) = | showAmountRoundedOrZero (Amount cur qty) = | ||||||
|     let rounded = printf "%.2f" qty in |     let rounded = punctuatethousands $ printf "%.2f" qty in | ||||||
|     case rounded of |     case rounded of | ||||||
|       "0.00"    -> "0" |       "0.00"    -> "0" | ||||||
|       "-0.00"   -> "0" |       "-0.00"   -> "0" | ||||||
|       otherwise -> (symbol cur) ++ rounded |       otherwise -> (symbol cur) ++ rounded | ||||||
| 
 | 
 | ||||||
|  | punctuatethousands :: String -> String | ||||||
|  | punctuatethousands s = | ||||||
|  |     sign ++ (punctuate int) ++ frac | ||||||
|  |     where  | ||||||
|  |       (sign,num) = break isDigit s | ||||||
|  |       (int,frac) = break (=='.') num | ||||||
|  |       punctuate = reverse . concat . intersperse "," . triples . reverse | ||||||
|  |       triples "" = [] | ||||||
|  |       triples s = [take 3 s] ++ (triples $ drop 3 s) | ||||||
|  | 
 | ||||||
| instance Num Amount where | instance Num Amount where | ||||||
|     abs (Amount c q) = Amount c (abs q) |     abs (Amount c q) = Amount c (abs q) | ||||||
|     signum (Amount c q) = Amount c (signum q) |     signum (Amount c q) = Amount c (signum q) | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NOTES
									
									
									
									
									
								
							| @ -3,7 +3,6 @@ hledger project notes | |||||||
| * TO DO | * TO DO | ||||||
| ** bugs | ** bugs | ||||||
| ** compatibility | ** compatibility | ||||||
| *** , in thousands |  | ||||||
| *** use greatest precision in register | *** use greatest precision in register | ||||||
| *** abbreviate 0 | *** abbreviate 0 | ||||||
| *** don't combine entries so much in register | *** don't combine entries so much in register | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -294,13 +294,16 @@ quickcheck = mapM quickCheck ([ | |||||||
|         ] :: [Bool]) |         ] :: [Bool]) | ||||||
| 
 | 
 | ||||||
| hunit = runTestTT $ "hunit" ~: test ([ | hunit = runTestTT $ "hunit" ~: test ([ | ||||||
|          "" ~: parseLedgerPatternArgs []                     @=? ([],[]) |          "" ~: parseLedgerPatternArgs []                     @?= ([],[]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["a"]                  @=? (["a"],[]) |         ,"" ~: parseLedgerPatternArgs ["a"]                  @?= (["a"],[]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["a","b"]              @=? (["a","b"],[]) |         ,"" ~: parseLedgerPatternArgs ["a","b"]              @?= (["a","b"],[]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--"]         @=? (["a","b"],[]) |         ,"" ~: parseLedgerPatternArgs ["a","b","--"]         @?= (["a","b"],[]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--","c","b"] @=? (["a","b"],["c","b"]) |         ,"" ~: parseLedgerPatternArgs ["a","b","--","c","b"] @?= (["a","b"],["c","b"]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["--","c"]             @=? ([],["c"]) |         ,"" ~: parseLedgerPatternArgs ["--","c"]             @?= ([],["c"]) | ||||||
|         ,"" ~: parseLedgerPatternArgs ["--"]                 @=? ([],[]) |         ,"" ~: parseLedgerPatternArgs ["--"]                 @?= ([],[]) | ||||||
|  |         ,"" ~: punctuatethousands "" @?= "" | ||||||
|  |         ,"" ~: punctuatethousands "1234567.8901" @?= "1,234,567.8901" | ||||||
|  |         ,"" ~: punctuatethousands "-100" @?= "-100" | ||||||
|         ,"" ~: test_ledgertransaction |         ,"" ~: test_ledgertransaction | ||||||
|         ,"" ~: test_ledgerentry |         ,"" ~: test_ledgerentry | ||||||
|         ,"" ~: test_autofillEntry |         ,"" ~: test_autofillEntry | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							| @ -1,6 +1,7 @@ | |||||||
| -- standard imports and utilities | -- standard imports and utilities | ||||||
| module Utils ( | module Utils ( | ||||||
|               module Utils, |               module Utils, | ||||||
|  |               module Char, | ||||||
|               module Data.List, |               module Data.List, | ||||||
|               module Data.Tree, |               module Data.Tree, | ||||||
|               module Text.Printf, |               module Text.Printf, | ||||||
| @ -10,6 +11,7 @@ module Utils ( | |||||||
|               module Test.HUnit |               module Test.HUnit | ||||||
|              ) |              ) | ||||||
| where | where | ||||||
|  | import Char | ||||||
| import Data.List | import Data.List | ||||||
| import Data.Tree | import Data.Tree | ||||||
| import Text.Printf | import Text.Printf | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user