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 cur qty) = | ||||
|     let rounded = printf "%.2f" qty in | ||||
|     let rounded = punctuatethousands $ printf "%.2f" qty in | ||||
|     case rounded of | ||||
|       "0.00"    -> "0" | ||||
|       "-0.00"   -> "0" | ||||
|       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 | ||||
|     abs (Amount c q) = Amount c (abs q) | ||||
|     signum (Amount c q) = Amount c (signum q) | ||||
|  | ||||
							
								
								
									
										1
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NOTES
									
									
									
									
									
								
							| @ -3,7 +3,6 @@ hledger project notes | ||||
| * TO DO | ||||
| ** bugs | ||||
| ** compatibility | ||||
| *** , in thousands | ||||
| *** use greatest precision in register | ||||
| *** abbreviate 0 | ||||
| *** don't combine entries so much in register | ||||
|  | ||||
							
								
								
									
										17
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -294,13 +294,16 @@ quickcheck = mapM quickCheck ([ | ||||
|         ] :: [Bool]) | ||||
| 
 | ||||
| hunit = runTestTT $ "hunit" ~: test ([ | ||||
|          "" ~: parseLedgerPatternArgs []                     @=? ([],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a"]                  @=? (["a"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b"]              @=? (["a","b"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--"]         @=? (["a","b"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--","c","b"] @=? (["a","b"],["c","b"]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["--","c"]             @=? ([],["c"]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["--"]                 @=? ([],[]) | ||||
|          "" ~: parseLedgerPatternArgs []                     @?= ([],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a"]                  @?= (["a"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b"]              @?= (["a","b"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--"]         @?= (["a","b"],[]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["a","b","--","c","b"] @?= (["a","b"],["c","b"]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["--","c"]             @?= ([],["c"]) | ||||
|         ,"" ~: parseLedgerPatternArgs ["--"]                 @?= ([],[]) | ||||
|         ,"" ~: punctuatethousands "" @?= "" | ||||
|         ,"" ~: punctuatethousands "1234567.8901" @?= "1,234,567.8901" | ||||
|         ,"" ~: punctuatethousands "-100" @?= "-100" | ||||
|         ,"" ~: test_ledgertransaction | ||||
|         ,"" ~: test_ledgerentry | ||||
|         ,"" ~: test_autofillEntry | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user