hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Can't use a quote as digit grouping character

Open iustin opened this issue 10 years ago • 3 comments

The documentation says:

Numbers […] can also have digit group separators at any position (eg thousands separators) which can be comma or period - whichever one you did not use as a decimal point.

However sometimes other characters are used as a separator, e.g. in Switzerland it's common to use the single quote. Would it be possible to support this? Either arbitrary characters or simply expanding the list of separators.

iustin avatar Jul 10 '15 21:07 iustin

This area is delicate already, but patches welcome.

simonmichael avatar Jul 10 '15 21:07 simonmichael

This looks similar to #330 . Here is a change on top of #639 :

diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs
index bc7ce7b4..5c0b8dfc 100644
--- a/hledger-lib/Hledger/Read/Common.hs
+++ b/hledger-lib/Hledger/Read/Common.hs
@@ -561,7 +561,7 @@ fromRawNumber negated raw = (quantity, precision, mdecimalpoint, mgrps) where
 
 rawnumberp :: TextParser m (Maybe Char, [String], Maybe (Char, String))
 rawnumberp = do
-    let sepChars = ['.', ','] -- all allowed punctuation characters
+    let sepChars = ['.', ',', '\''] -- all allowed punctuation characters
 
     (firstSep, groups) <- option (Nothing, []) $ do
         leadingDigits <- some digitChar

ony avatar Nov 02 '17 23:11 ony

Currently, a narrow non-breaking space (U+202F) or a thin space (U+2009) cannot be used for digit grouping. Multiple standards bodies follow that for digit grouping. It might be desirable to support that.

https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping

​ISO 80000-1 (which superseded ISO 31-0) states in its chapter 7.3.1 (Numbers, General):

To facilitate the reading of numbers with many digits, these may be separated into groups of three, counting from the decimal sign towards the left and the right. No group shall contain more than three digits. Where such separation into groups of three is used, the groups shall be separated by a small space and not by a point or a comma or by any other means.

This is also the recommendation of the International System of Units (SI) brochure:

5.3.4 Formatting numbers, and the decimal marker ... Following the 9th CGPM (1948, Resolution 7) and the 22nd CGPM (2003, Resolution 10), for numbers with many digits the digits may be divided into groups of three by a thin space, in order to facilitate reading. Neither dots nor commas are inserted in the spaces between groups of three. However, when there are only four digits before or after the decimal marker, it is customary not to use a space to isolate a single digit. The practice of grouping digits in this way is a matter of choice; it is not always followed in certain specialized applications such as engineering drawings, financial statements, and scripts to be read by a computer.

the-solipsist avatar Jul 19 '22 12:07 the-solipsist