From: Gavin Kistner Date: 2005-11-01T23:58:25+09:00 Subject: Re: Newbie: How to format a number to always show two decimals? On Nov 1, 2005, at 7:49 AM, David A. Black wrote: > On Tue, 1 Nov 2005, Gavin Kistner wrote: >> On Oct 31, 2005, at 5:41 PM, David A. Black wrote: >>> Aside to Phrogz: is that left over from a game of code golf?? :-) >> LOL. No, before I grokked sprintf, I needed the round_to >> functionality. That's a port of the Number.toFixed algorithm from >> section 15.7.4.5 of the ECMAScript (ECMA-262) specs: > Interesting pedigree. > > It was the semi-colons and the vacuum-packed syntax that made me think > it might be a multi-line split-out of a former golf entry :-) Ah, no. Upon reflection, those are because the ruby code is actually a port of my JavaScript version of that algorithm. Microsoft's own implementation of Number.toFixed did not (at some point, perhaps currently) conform to that algorithm (and other JS engines did not at some point support that method, despite it being part of the spec) so I wrote my own JS-only port to patch bad engines as needed. When it came time to for the Ruby version, a bit of syntax conversion seems to be all I did. At the point in my life when I wrote the JS version, I was very into very terse formatting. Whitespace seemed to be at a premium during that dark period. :)