About 2,420,000 results
Open links in new tab
  1. get decimal part of a float number in python - Stack Overflow

    May 7, 2015 · n=(float(input('Enter the Decimal Value: '))) n1=(str(n)) l=0 s='' for c in n1: if c=='.' or l==1: l=1 if c!='.': s+=c#storing the decimal part # Converting the decimal part to the integer part print('0.{0}'.format(int(s)))

  2. python - Easy way of finding decimal places - Stack Overflow

    Apr 5, 2022 · import decimal def find_decimals(value): return (abs(decimal.Decimal(str(value)).as_tuple().exponent)) # Floats print (find_decimals(123.45678)) print (find_decimals(0.00001)) # Scientific Notation print (find_decimals(1e-05)) # Strings print (find_decimals('123.45678')) print (find_decimals('0.00001')) print (find_decimals('1e-05'))

  3. How do I make a float only show a certain amount of decimals

    import math def truncate(number, digits) -> float: places = len(str(number)[str(number).find("."):]) if places > 6: stepper = 10.0 ** digits return math.trunc(stepper * number) / stepper else: return str(number) + "0"*(6 - places)

  4. 3 Python ways to Limit float up to two decimal places

    In this article we will discuss about the a very popular use case of the floating-point numbers i.e., Limiting the float up to two decimal places. Python has a variety of Data Types which are used to specify the category of the value that can be stored inside a variable.

  5. Print floats to a specific number of decimal points in Python

    Various methods can be used to print floats to a specific number of decimal points in Python. Methods: round (), format () function, format specifier "%f".

  6. How to Get the Decimal Part of a Number in Python? - Python

    Jan 10, 2025 · Python offers several ways to extract the decimal part of a number. Here, I’ll cover the most common methods: Method 1. Use the Modulo Operator. The modulo operator (%) is a simple and effective way to extract the decimal part of a float. Here’s how you can do it: return number % 1. Output:

  7. How to extract the decimal part (or fractional part) of a float

    Apr 14, 2021 · Examples of how to extract the decimal part (or fractional part) of a number in python: Let's consider the following float number: returns. To extract the decimal part a solution is to use the modulo operator % returns. Note: Another solution is to use round () returns. Note: How to get numbers after decimal point? How to round a number in python ?

  8. Split a Float into Integer and Decimal parts in Python

    Use the `math.modf ()` method to split a number into integer and decimal parts, e.g. `result = math.modf (my_num)`.

  9. Precision Handling in Python - GeeksforGeeks

    Aug 9, 2024 · In Python, we can handle precision values using Decimal Module. In this example, we will see How to Limit Float to Two Decimal Points in Python. In Python float precision to 2 floats in Python, and in Python float precision to 3. There are many ways to set the precision of the floating-point values. Some of them are discussed below.

  10. decimalDecimal fixed-point and floating-point arithmetic — Python

    5 days ago · Decimal instances can be constructed from integers, strings, floats, or tuples. Construction from an integer or a float performs an exact conversion of the value of that integer or float.

Refresh