Built-in format Function

Built-in format Function

  • The format function is used to produce a numeric string version of a floating-point value with a specific number of decimal places.
  • It allows controlling the precision and formatting of numeric values in string output.

Examples:

Rounding to Two Decimal Places:

The format specifier '.2f' rounds the result to two decimal places.

Scientific Notation:

    The value is formatted in scientific notation with six decimal places of precision.

    Formatting with Comma Separators:

    Comma separators are added to the result for better readability.

    Design a site like this with WordPress.com
    Get started