Chapter 14.8.3. Other String Formatting Functions

MochiKit includes the following additional simple functions for formatting values.

  • lstrip(str, chars=”\s”) Strips off the whitespace on the left of the string, or strips off any characters that match the chars regular expression

  • rstrip(str, chars=”\s”) Strips whitespace off of the right of the string

  • strip(str, chars=”\s”) Strips whitespace off of the right and left

  • roundToFixed(num, precision) Returns a string with num rounded to precision digits with trailing zeros (and works consistently across browsers)

  • truncToFixed(num, precision) Returns a string with num truncated to precision digits

  • twoDigitAverage(numerator, denominator) Returns numerator/denominator rounded to two digits, with ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.