Help

Frequently asked questions and other useful tidbits.

Format Class

Updated on April 25th, 2008

This is a helper class that allows you to format values.

money(number, withCommas)

Formats a number into money with or without commas (false by default).

Format.money(9.3); # => "9.30"
Format.money(1000); # => "1000.00"
Format.money(1000, true); # => "1,000.00"

commas(number)

Adds commas to a number. (used by the money method)

Format.money(1000, true); # => "1,000"

pluralize(count, singular, plural)

Returns the singular version of a word if there are one, and the plural version otherwise.

Format.pluralize(1, 'dog', 'dogs'); # => "1 dog"
Format.pluralize(2, 'dog', 'dogs'); # => "2 dogs"

version(versionString)

Returns numeric value of a version string. Useful for verifying versions of JavaScript libraries.

Format.version('1.6.0.1'); # => 1.601
Format.version(Prototype.Version) < 1.5 ? alert('No!') : alert('Yes!');

Contact

Can’t find an answer to your question? No worries, we’re here to help.