| | |
| | | elif type == "prefix": |
| | | return PrefixFloatFormatter(arglist) |
| | | elif type == "dec" or type == "decimal": |
| | | return EngFloatFormatter(arglist) # fallback to engineering |
| | | return DecFloatFormatter(arglist) |
| | | else: |
| | | return None |
| | | |
| | |
| | | def getValue(self, string): |
| | | return string |
| | | |
| | | class DecFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |
| | | if len(formatparameters) != 1: |
| | | raise Exceptions.WrongParameters("Dec format accept only one argument") |
| | | self.precision = int(formatparameters[0]) |
| | | |
| | | def toFormat(self, num): |
| | | try: |
| | | num = float(num) |
| | | except ValueError: |
| | | raise ValueError |
| | | except TypeError: |
| | | raise ValueError |
| | | |
| | | |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f}").format(num).replace(".", ",\!") |
| | | ) |
| | | |
| | | def getValue(self, num): |
| | | val = ("{:." + str(self.precision - 1) + "f}").format(num) |
| | | return float(val) |
| | | |
| | | |
| | | |
| | | class SciFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |