Hi, You can check out ascb (ActionScript Cook Book), a library with some useful functions. In this case, the class NumberFormat, and the method format may do the job.
http://www.rightactionscript.com/ascb/ Almost any formatNumber method you can find in many other libraries will help you too, except for some reason you want to roll your own. Cheers Juan Pablo Califano 2008/7/2, Allandt Bik-Elliott (Receptacle) <[EMAIL PROTECTED]>: > > hey > > i am using regexp to inject commas into my years by searching for 000 and > replacing with ,000 like this > > var pattern:RegExp = /000/; > sYear = sYear.replace(pattern, ",000"); > > however, this approach will bug every multiple of 10,000 as there are more > zeros than the pattern expects. > > is there a way of counting back from the end of the number and inserting > the comma (even without a regular expression)? if i use the g modifier in > the regexp (so var pattern:RegExp = /000/g;), it will only pick up the first > 000 (and every multiple thereafter) instead of leaving the first 0 (which is > expected behaviour but something i'd like to get around) > > would you use an if statement to count the length of the sYear string or is > there a better way? > > at the moment, because i know that i only need years from 15,000 bc, i'm > doing this: > > var sYear:String = String(nYear); > if (sYear.length > 5) > { > if (sYear != "-10000") > { > var pattern:RegExp = /000/; > sYear = sYear.replace(pattern, > ",000"); > } else { > var pattern:RegExp = /0000/; > sYear = sYear.replace(pattern, > "0,000"); > } > } > > which is a bit hacky and limited > > interested to hear your answer > > a > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

