Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Integer formatting

 [1/5] from: swhite:ci:bloomington:mn:us at: 10-Feb-2006 11:14


Wow! Those demos! I didn't quite realize that REBOL could do that. I am mentally stuck in the days of mainframe programming when processors were slow, memory was small, and interpreters were slow. But back to Dullsville, can anyone tell me how to do this? I want to assemble the year, month, and day into a string (YYYYMMDD) to use in a file name. The following line almost does it: print join to-string now/year [to-string now/month to-string now/day] BUT, if the month or day is a single digit, I don't know how to pad it out with a leading zero. For example, February 10, 2006 comes out as 2006210 when I want 20060210. Thank you for any help. Steven White City of Bloomington 1800 W Old Shakopee Rd Bloomington MN 55431-3096 USA 952-563-4882 (voice) 952-563-4672 (fax) steven.white-ci.bloomington.mn.us

 [2/5] from: sags:apollo:lv at: 10-Feb-2006 19:27


This ir solution of mine, that I using together with round function from library: pad-decimal: func [ value [number!] len [integer!] /local s] [ s: form value either len > 0 [ either all [ value = to-integer value ] [ head insert/dup tail s #"0" len - ((length? s) - index? find s #".") ][ s: form either any [ greater? abs value 0.1 value = 0 ] [ to-string value ][ replace insert to-string ( value / abs value ) + value "0" "1." "0." ] head insert/dup tail s #"0" len - ((length? s) - index? find s #".") ] ][ copy/part s index? back find s "." ] ] Janeks On 10 Feb 2006 at 11:14, Steven White wrote:

 [3/5] from: carl::cybercraft::co::nz at: 10-Feb-2006 21:08


On Friday, 10-February-2006 at 11:14:18 Steven White wrote,
>I want to assemble the year, month, and day into a string (YYYYMMDD) to >use in a file name. The following line almost does it: > >print join to-string now/year [to-string now/month to-string now/day]
Try a function something like this... pad: func [value length char][ join to-string array/initial length - length? to-string value char value ] That allows padding of numbers as well as other values, thus can be used so...
>> pad 10 4 "0"
== "0010"
>> pad "aa" 4 " "
== " aa"
>> pad 100 2 "0"
== "100" (That last one shows it doesn't strip characters if the padding's not enough.)
>> join to-string now/year [pad now/month 2 "0" pad now/day 2 "0"]
== "20060211" Hope that helps. -- Carl Read.

 [4/5] from: compkarori:gm:ail at: 11-Feb-2006 1:14


rejoin [ now/year reverse copy/part reverse join 0 now/month 2 reverse copy/part reverse join 0 now/day 2 ] == "20060211" On 2/11/06, Steven White <swhite-ci.bloomington.mn.us> wrote:
> > I want to assemble the year, month, and day into a string (YYYYMMDD) to > use in a file name. The following line almost does it: >
-- Graham Chiu http://www.compkarori.com/emr/

 [5/5] from: SunandaDH::aol::com at: 10-Feb-2006 17:32


Steven:
> I want to assemble the year, month, and day into a string (YYYYMMDD)
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=to-iso-8601-da te.r Sunanda.