Name

MochiKit.Format - string formatting goes here

Synopsis

assert( twoDigitAverage(1, 0) == "0" );
assert( twoDigitFloat(1.2345) == "1.23" );
assert( twoDigitFloat(1) == "1" );
assert( percentFormat(1.234567) == "123.45%" );

assert( thisModuleNeedsMoreStuff );

Description

Formatting strings and stringifying numbers is boring, so a couple useful functions in that domain live here. So far, there's not much to see here.

Dependencies

None.

API Reference

Functions

twoDigitAverage(numerator, denominator):

Calculate an average from a numerator and a denominator and return it as a string with two digits of precision (e.g. "1.23").

If the denominator is 0, "0" will be returned instead of NaN.

twoDigitFloat(someFloat):

Roughly equivalent to: sprintf("%.2f", someFloat)

percentFormat(someFloat):

Roughly equivalent to: sprintf("%.2f%%", someFloat * 100)

Authors