Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def format_decimal(number, precision):
- """
- Format a decimal number to a specific precision.
- Args:
- number (float): The decimal number to be formatted.
- precision (int): The desired number of decimal places.
- Returns:
- str: The formatted decimal number.
- """
- return f"{number:.{precision}f}"
- # Example usage:
- number = 3.141592653589793
- precision = 3
- formatted_number = format_decimal(number, precision)
- print(formatted_number) # Output: 3.142
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement