5 examples of 'float to int python' in Python

Every line of 'float to int 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``6def convert_string_to_float_int(string):78    if isinstance(string, six.string_types):9        try:10            # evaluate the string to float, int or bool11            value = literal_eval(string)12        except Exception:13            value = string14    else:15        value = string1617    # check if the the value is float or int18    if isinstance(value, float):19        if value.is_integer():20            return int(value)21        return value22    return value``
``78def bits2float( bits ):7980  # This is a bit convoluted, but this is much faster than ieee.pack81  # stuff. In addition to normal casting through uint2singlefloat, we have82  # additional casting because integer and float types that we can do83  # arithmetic operations on are standard Python sizes (native machine84  # size). Here's the typing going on below:85  # Python Int (64-bit) -&gt; r_uint32 -&gt; r_singlefloat -&gt; Python Float (64-bit)86  flt = rffi.cast( lltype.Float, uint2singlefloat( r_uint32( bits ) ) )87  return flt``
``141def int_or_float(x):142    try:143        return int(x)144    except ValueError:145        return float(x)``
``84def to_float(num):85    """Convert anything to float."""86    return float(to_num(num))``
``391def magic_int2float(magic_int):392    """Convert a Python magic int into a 'canonic' floating-point number,393    e.g. 2.7, 3.7. runtime error is raised if "version" is not found.394395    Note that there can be several magic_int's that map to a single floating-396    point number. For example 3320 (3.5.a0), 3340 (3.5b1), and 3351 (3.5.2)397    all map to 3.5.398    """399    return py_str2float(magicint2version[magic_int])``