Commatizing numbers: Difference between revisions

→‎{{header|Factor}}: change word names, more descriptive stack effects, use existing "replace" word
(Add Factor)
(→‎{{header|Factor}}: change word names, more descriptive stack effects, use existing "replace" word)
Line 308:
{{works with|Factor|0.99 2020-01-23}}
<lang factor>USING: accessors grouping io kernel math regexp sequences
splitting strings unicode ;
 
: first-numeric ( str -- slicenew-str ) R/ [1-9][0-9]*/ first-match ;
R/ [1-9][0-9]*/ first-match >string ;
 
: commatize-numbercommas ( numeric-str period sepseparator -- new-str )
[ reverse ] [ group ] [ reverse join reverse ] tri* ;
 
: (commatize) ( text from period sepseparator -- str )
[ cut first-dup numeric dup >string ] 2dip commatize-numbercommas replace append swap;
[ from>> ] [ to>> ] [ seq>> snip surround append ] tri ;
 
: commatize* ( text from period sep -- str )
1,808

edits