Every line of 'how to print a float in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
21 def visitFloat(self, node: AST.Float): 22 print(indent * node.printLevel, node.value)
42 def format_printable_data(data, float_format=_DEFAULT_FLOAT_FORMAT): 43 t = type(data) 44 if t is np.ndarray: 45 return 'ndarray{}, dtype={}'.format(data.shape, data.dtype) 46 # Handle torch.tensor 47 if 'Tensor' in str(t): 48 return 'tensor{}, dtype={}'.format(tuple(data.shape), data.dtype) 49 elif t is float: 50 return float_format.format(data) 51 else: 52 return str(data)
5 def fmtFloat(n): 6 return '{:6.3f}'.format(n)
119 def dump_float(self, x): 120 write = self._write 121 write(TYPE_FLOAT) 122 s = `x` 123 write(chr(len(s))) 124 write(s)
4 def format_float_text(value): 5 v = value 6 if isinstance(v, u.Quantity): 7 v = value.value 8 elif isinstance(v, str): 9 v = float(value) 10 11 if 0.001 <= abs(v) <= 1000 or abs(v) == 0.0: 12 return "{0:.3f}".format(value) 13 else: 14 return "{0:.3e}".format(value)
48 def format_float(x): 49 try: 50 return "%10.5f" % x 51 except: 52 return str(x)