from typing import Optional
import math


def float_toascii(data: float, infinite: 'Optional[str]' = None) -> str:
    """Convert :obj:`float` to ASCII.

    Args:
        data: A :obj:`float` number.
        infinite: The ASCII representation of infinite numbers (``NaN`` and infinity).

    Returns:
        The converted ASCII string.

    Example:
        When converting a :obj:`float` number, for example::

            >>> f = -123.123456789

        the function will preserve only **6 digits** of its fractional part,
        i.e.::

            >>> float_toascii(f)
            '-123.123456'

    Note:
        Infinite numbers, i.e. ``NaN`` and infinity (``inf``), will be
        converted as the value specified in ``infinite``, in default the string
        representation of the number itself, i.e.:

        * ``NaN`` -> ``'nan'``
        * Infinity -> ``'inf'``

    """
    if not math.isfinite(data):
        if infinite is None:
            return str(data)
        return infinite
    int_part, flt_part = str(data).split('.')
    return '%s.%s%s' % (int_part,
                        flt_part[:6],
                        '0' * (6 - len(flt_part)))