Nokia 5310 XpressMusic iSync Plug-In

March 18th, 2008

iSync Plug-In for Nokia 5310 XpressMusic mobile phone packed as an easy to install Mac OS X package.

Thanks to James Lloyd for a MetaClasses.plist file content.

How to round decimal numbers in Python

October 28th, 2007

How to round Decimal numbers with Symmetric Arithmetic Rounding (as described in article “Rounding” on wikipedia.org?.

Rounding can be done with decimal.Decimal object’s quantize method. Use decimal.ROUND_HALF_UP flag to get a Symmetric Arithmetic Rounding.

For example:

>>> from decimal import Decimal, ROUND_HALF_UP
>>> Decimal("234.4535").quantize(Decimal("0.001"), ROUND_HALF_UP)
Decimal("234.454")
>>> Decimal("234.4534").quantize(Decimal("0.001"), ROUND_HALF_UP)
Decimal("234.453")
>>> Decimal("-234.4535").quantize(Decimal("0.001"), ROUND_HALF_UP)
Decimal("-234.454")
>>> Decimal("-234.4535").quantize(Decimal("0.001"), ROUND_HALF_UP)
Decimal("-234.454")

So, the “traditional” round function will look like this:

from decimal import Decimal, ROUND_HALF_UP

def round(d, digits=0):
    """
    Symmetric Arithmetic Rounding for decimal numbers

    d       - Decimal number to round
    digits  - number of digits after the point to leave

    For example:
    >>> round(Decimal("234.4536"), 3)
    Decimal("234.454")
    >>> round(Decimal("234.4535"), 3)
    Decimal("234.454")
    >>> round(Decimal("234.4534"), 3)
    Decimal("234.453")
    >>> round(Decimal("-234.4535"), 3)
    Decimal("-234.454")
    >>> round(Decimal("234.4535"), -1)
    Decimal("2.3E+2")
    """
    return d.quantize(Decimal("1") / (Decimal('10') ** digits), ROUND_HALF_UP) 

Docbook to SCORM Converter is open source

May 20th, 2007

Docbook to SCORM Converter is now open source. It’s released under GNU Lesser General Public License. Source code and binary files can are available from the project site at Google Code.

See updated description and usage instructions.