Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!natinst!rpp386!jfh From: jfh@rpp386.cactus.org (John F. Haugh II) Newsgroups: comp.lang.perl Subject: Re: Is this how formats are supposed to work? Summary: How about this ... Message-ID: <17678@rpp386.cactus.org> Date: 17 Jan 90 05:57:55 GMT References: <1990Jan15.185922.20098@eci386.uucp> <6798@jpl-devvax.JPL.NASA.GOV> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 44 In article <6798@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: I-In article <1990Jan15.185922.20098@eci386.uucp> clewis@eci386 (Chris Lewis) writes: n-: Is there any way to set the display format for numbers in format lines? e- w-No. s- --: Assigning "%.2g" to $# (after selecting the handling associated with the n-: stream) doesn't appear to affect anything and things are printed with o-: more than 2 decimal places. i- s-Maybe it should work this way--I haven't thought about it. Or maybe we e-need numeric "pictures". Perhaps a function "picture" that takes two arguments - the first a number, either floating point or integer, and a picture string. The function formats the number according to the picture string. [ Anyone familiar with INFORMIX[tm] RDBMS can quit now ... ] The format characters would be < - left justify numeric # - blank-fill numeric & - zero-fill numeric * - star-fill numeric [ for bank drafts, etc ] , - literal comma, unless a space is to the left . - literal decimal point $ - dollar sign in first blank left of number () - show sign ala accounting statements - - [ minus sign ] blank for positive, '-' for negative + - '+' for positive, '-' for negative The values and pictures below would give the following results - value "$<,<<&.##" "#,###.##" "*,***.##" "&&&&" 0.01 -> "$0.01" " .01" "*****.01" "0000" 0.12 -> "$0.12" " .12" "*****.12" "0000" 1.23 -> "$1.23" " 1.23" "****1.23" "0001" 12.34 -> "$12.34" " 12.34" "***12.34" "0012" 123.45 -> "$123.45" " 123.45" "**123.45" "0123" 1234.56 -> "$1,234.56" "1,234.56" "1,234.56" "1234" -- John F. Haugh II UUCP: ...!cs.utexas.edu!rpp386!jfh Ma Bell: (512) 832-8832 Domain: jfh@rpp386.cactus.org