From: Josef 'Jupp' SCHUGT Date: 2005-04-27T02:29:36+09:00 Subject: Re: Implementing COBOL style number formatting (Was: Any guides for good coding in Ruby?) At Mon, 25 Apr 2005 03:35:09 +0900, Michael Campbell wrote: > One small nit; "Debit" is usually indicated (counter-intuitively) by > "DR", not "DB" (though I have seen both.) No idea if there is a > standard for this, or what it says. According to my COBOL tutorial (I currently don't have a COBOL compiler up and running) COBOL uses "DB". After some careful analysis of the PIC strings I came to the conclusion that they have too many shortcomings. I am presently considering some "%xyz" notation that removes them. Only non-digits are used so that prefixing xyz with a digit string can be used to express repetition. I tried my best to make the formatting strings mnemonic. It seems to make sense to allow for customization of what 'c' and 'd' are displayed as. Comments are welcome and essential: 1 digit ("_") digit is displayed using "_". prefix controls zero. 1.1 blank zero ("_" or " _") prefix " " displays zero as " ". default. 1.2 show zero ("!_") prefix "!" displays zero as "0". 1.3 secure ("*_") prefix "*" displays zero as '*'. 2 sign ("-") sign is displayed using '-'. prefix controls non-negative sign. 2.1 blank non-negative sign (" -") prefix " " displays non-negative sign as " ". default. prefix controls zero's sign. 2.1.1 blank zero's sign (" -") prefix " " displays zero's sign as " ". default. 2.1.2 positive zero's sign ("+ -") prefix "+" displays zero's sign as "+". 2.1.3 negative zero's sign ("- -") prefix "-" displays zero's sign as "-". 2.1.4. secure zero's sign ("* -") prefix "*" displays zero's sign as "*". 2.2 show non-negative (sign ("+-") prefix "+" displays non-negative sign as "+". 2.2.1 blank zero's sign prefix " " displays zero's sign as " ". 2.2.2 positive zero's sign prefix "+" displays zero's sign as "+". default. 2.2.3 negative zero's sign prefix "-" displays zero's sign as "-". 2.2.4 secure zero's sign prefix "*" displays zero's sign as '*' 2.3 secure non-negative sign ("*-") prefix "*" displays non-negative sign as "*". prefix controls display of zero's sign. note that prefix " " is prohibited because it would contradict purpose of "*". 2.3.1 positive zero's sign ("+*-") prefix "+" displays zero's sign as "+". 2.3.2 negative zero's sign ("-*-") prefix "-" displays zero's sign as "-" 2.3.3 secure zero's sign ("**-") prefix "*" displays zero's sign as "*". default. 2.4 shortcuts default rules are such that shorthands exist for most likely displays of sign (most likely is only displaying negative sign, next is displaying zero's sign as if zero were positive). 2.4.1 "-" has same meaning as " -" and " -": displays "-" if negative, ' ' otherwise 2.4.2 "+-" has same meaning as "++-": displays "-" if negative, "+" otherwise. 2.4.3 "*-" has same meaning as "**-": displays "-" if negative, "*" otherwise. 3 separator (",") separator is displayed using ",". Prefix controls behavior if no non-zero digits preceed. 3.1 blank separator (" ,") displays " " in place of "," if no non-zero digits preceede. default. 3.2 secure separator ("*,") displays "*" in place of "," if no non-zero digits preceed. 4. decimal point (".") decimal point is displayed using "." 5. currency symbol ("$") currency symbol is displayed using "$". 6. credit ("c") displays 'CR' in the case of credit (i.e. a value smaller than zero). prefix controls display in case of non-credit. 6.1 blank credit (" c") displays two blanks (" ") in case of non-credit 6.2 secure credit ("*c") displays two asterisks ("**") in case of non-credit 6.3 zero is credit ("!c", "! c", "!*c") zero is assumed to be credit. default is not to do this. 7. debit ("d") displays 'DB' in the case of debit (i.e. a value not smaller than zero). prefix controls display in case of non-debit 7.1 blank debit (" d") displays two blanks (" ") in case of non-debit. 7.2 secure debit ("*d") displays two asterisks ("**") in case of non-debit. 7.3 zero is debit ("!d", "! d", "!*d") zero is assumed to be debit. default is not to do this. Josef 'Jupp' Schugt -- Hab nun ach, Thunderbird, Mutt, Mew, Pine und leider auch Outlook durchaus studiert, mit heissem Bemuehn. Hier steh ich nun, ich armer Tor - und kram den Wanderlust hervor :-)