Every line of 'convert float to string 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.
6 def convert_string_to_float_int(string): 7 8 if isinstance(string, six.string_types): 9 try: 10 # evaluate the string to float, int or bool 11 value = literal_eval(string) 12 except Exception: 13 value = string 14 else: 15 value = string 16 17 # check if the the value is float or int 18 if isinstance(value, float): 19 if value.is_integer(): 20 return int(value) 21 return value 22 return value
48 def format_float(x): 49 try: 50 return "%10.5f" % x 51 except: 52 return str(x)
23 def textToFloat( value ): 24 if ',' in value and '.' in value: 25 commaIndex = value.rfind(',') 26 periodIndex = value.rfind('.') 27 if commaIndex > periodIndex: 28 newValue = value.replace( '.', '' ).replace( ',', '.' ) 29 else: 30 newValue = value.replace( ',', '' ) 31 elif ',' in value: 32 newValue = value.replace( ',', '.' ) 33 else: 34 newValue = value 35 # Remove spaces 36 newValue = newValue.replace( ' ', '' ) 37 # Remove possible coin symbol in the end 38 if not newValue[-1] in '0123456789': 39 newValue = newValue[:-1] 40 return float( newValue )
175 def conv_to_float(self,obj): 176 try: 177 float_obj = float(obj) 178 return float_obj, True 179 except ValueError: 180 return None, False
66 def test_float(self): 67 self.assertEqual(sqlrepr(10.01), "10.01")
276 def _float_to_json(value): 277 """Coerce 'value' to an JSON-compatible representation.""" 278 return value
28 def to_float(value): 29 ''' 30 Returns the money value as a float. 31 ''' 32 return value / float(INTERNAL_FACTOR)
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)
33 def conv(value): 34 if value == False: 35 return '' 36 else: 37 return locale.format('%.' + str(self.digits[1]) + 'f', 38 value or 0.0, True)
161 def _cast_from_str(self, value): 162 return float(value)