| | |
| | | pass |
| | | |
| | | def toFormat(self, string): |
| | | return string.replace("\"", "") |
| | | return string.replace('"', "") |
| | | |
| | | def getValue(self, string): |
| | | return "\"{}\"".format(str(string.replace("\"", ""))) |
| | | return '"{}"'.format(str(string.replace('"', ""))) |
| | | |
| | | |
| | | class DecFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |
| | |
| | | except TypeError: |
| | | raise ValueError |
| | | |
| | | num=float(("{:."+str(self.precision-1)+"e}").format(num)) |
| | | places=self.fexp(num) |
| | | num = float(("{:." + str(self.precision - 1) + "e}").format(num)) |
| | | places = self.fexp(num) |
| | | |
| | | decimal_places=self.precision-places-1 |
| | | if(decimal_places<0): |
| | | decimal_places=0 |
| | | format_str="{:"+str(places)+"."+str(decimal_places)+"f}" |
| | | decimal_places = self.precision - places - 1 |
| | | if decimal_places < 0: |
| | | decimal_places = 0 |
| | | format_str = "{:" + str(places) + "." + str(decimal_places) + "f}" |
| | | |
| | | return format_str.format(num).replace(".", ",\!") |
| | | |
| | | |
| | | def getValue(self, num): |
| | | |
| | | num = float(("{:." + str(self.precision - 1) + "e}").format(num)) |
| | | places = self.fexp(num) |
| | | |
| | | num=float(("{:."+str(self.precision-1)+"e}").format(num)) |
| | | places=self.fexp(num) |
| | | |
| | | decimal_places=self.precision-places-1 |
| | | if(decimal_places<0): |
| | | decimal_places=0 |
| | | format_str="{:"+str(places)+"."+str(decimal_places)+"f}" |
| | | val=format_str.format(num) |
| | | decimal_places = self.precision - places - 1 |
| | | if decimal_places < 0: |
| | | decimal_places = 0 |
| | | format_str = "{:" + str(places) + "." + str(decimal_places) + "f}" |
| | | val = format_str.format(num) |
| | | return float(val) |
| | | |
| | | |
| | | |
| | | class SciFloatFormatter(FormatterFactory): |
| | |
| | | raise ValueError |
| | | except TypeError: |
| | | raise ValueError |
| | | |
| | | # Clip precision firstly |
| | | num = float(("{:." + str(self.precision - 1) + "e}").format(num)) |
| | | exp = self.fexp(num) |
| | | man = self.fman(num) |
| | | (exp, man) = self.realign3(exp, man) |
| | | decimal_places = self.precision - self.fexp(man) - 1 |
| | | if decimal_places < 0: |
| | | decimal_places = 0 |
| | | if exp == 0: |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f}").format(man).replace(".", ",\!") |
| | | ) |
| | | return ("{:." + str(decimal_places) + "f}").format(man).replace(".", ",\!") |
| | | else: |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f} \cdot 10^{{{}}}") |
| | | ("{:." + str(decimal_places) + "f} \cdot 10^{{{}}}") |
| | | .format(man, int(exp)) |
| | | .replace(".", ",\!") |
| | | ) |
| | |
| | | raise ValueError |
| | | except TypeError: |
| | | raise ValueError |
| | | |
| | | # Clip precision firstly |
| | | num = float(("{:." + str(self.precision - 1) + "e}").format(num)) |
| | | exp = self.fexp(num) |
| | | man = self.fman(num) |
| | | (exp, man) = self.realign3(exp, man) |
| | | decimal_places = self.precision - self.fexp(man) - 1 |
| | | if decimal_places < 0: |
| | | decimal_places = 0 |
| | | if exp == 0: |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f}\,").format(man).replace(".", ",\!") |
| | | ("{:." + str(decimal_places) + "f}\,").format(man).replace(".", ",\!") |
| | | ) |
| | | else: |
| | | prefix = self.exp2prefix(exp) |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f}\,\mathrm{{{}}}") |
| | | ("{:." + str(decimal_places) + "f}\,\mathrm{{{}}}") |
| | | .format(man, prefix) |
| | | .replace(".", ",\!") |
| | | ) |