From: Austin Ziegler Date: 2004-01-01T04:29:37+09:00 Subject: Re: Overriding to_s You probably don't want to override #to_s to take a parameter. I recommend looking at http://rubyforge.org/projects/extensions/; specifically #format_s as defined in extensions/lib/extensions/numeric.rb. I have submitted a replacement for extensions/lib/extensions/numeric.rb that handles (simple before/after) currency formatting. If anything more complex is necessary, please let me know and I'll look into it. There are three possible further extensions to this method from my perspective. First, this method does not ensure precision, but instead formats exactly what is given. The :usd style provided will format 1234.1234 as $1,234.1234. If you only want $1,234.12, it is up to you to ensure that only the proper number of decimal places is provided. It may be useful to provide for precision (both decimal and general). Second, it may be desirable to show the "+" sign in some instances. This is not yet possible. Finally, it may be desirable to have a parallel method, #format_a, that returns the formatted constituent parts of the number as an array [sign, integer-part, decimal-point, decimal-part] so that you can format them as you wish. The simplest formatting of #format_a would be #join, but you could do: ($1.20) instead of $(1.20). (The currency formatting takes place after all other formatting.) (Alternatively, one could specify a template, but that is overkill in my opinion.) -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.12.31 * 12.22.28