Skip to main content

Excel-style number formatting for Python.

Project description

q2numfmt

PyPI version License Python

q2numfmt is a lightweight Python package for formatting numeric data using Excel-style number format strings. It follows the ECMA-376 - Office Open XML file formats - 5th edition, December 2021 specification—the same standard used by Microsoft Excel to format numbers.

Features

  • Format integer, float, string, or Decimal values.
  • Supports custom Excel-like format strings (e.g. "0.00", "0%", "$#,##0.00").
  • Implements rules from ECMA-376 Part 1, Section 18.8.31 (numFmts).
  • No external dependencies.
  • Ideal for spreadsheet tools, reports, exports, and other data presentation needs.

Installation

pip install q2numfmt

Usage

from q2numfmt import format_number

print(format_number(1234.567, "#,##0.00"))     # "1,234.57"
print(format_number("0.056", "0.0%"))          # "5.6%"
print(format_number(-1234.5, "$#,##0.00"))     # "-$1,234.50"
print(format_number(0, '[Green]0.00;[Red]-0.00'))  # "0.00"

API

format_number(value, format_string)

Formats a number using an Excel-style number format string.

value: int, float, str, or decimal.Decimal

format_string: A string format as defined in Excel / ECMA-376

Returns a str with the formatted result.

Example Format Strings

Format String Input Output 0.00 12.3 12.30 #,##0 12345 12,345 0.0% 0.1234 12.3% $#,##0.00 -1234.5 -$1,234.50 [Red]-0.0 -5.5 -5.5

Specification

The package is based on:

ECMA-376-1:2016, Part 1 – Office Open XML File Formats

Section 18.8.31: numFmts (Custom Number Formats in Excel)

License

This project is licensed under the MIT License – see the LICENSE file for details.

Links

📦 PyPI: https://pypi.org/project/q2numfmt

🧑‍💻 GitHub: https://github.com/AndreiPuchko/q2numfmt

Author

Andrei Puchko GitHub: https://github.com/AndreiPuchko

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

q2numfmt-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

q2numfmt-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file q2numfmt-0.1.0.tar.gz.

File metadata

  • Download URL: q2numfmt-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.7 Windows/10

File hashes

Hashes for q2numfmt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07bad5d9520a16c2a31ae6defe71bd0192522b911dd077eb001a45469260b0eb
MD5 5e11c63d716de88ff052cbb60fbbaf1a
BLAKE2b-256 aa49d80cdb94da5e39d97ca1306b4ac1ed8e10737ea2947e657bcb6adf792c14

See more details on using hashes here.

File details

Details for the file q2numfmt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: q2numfmt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.7 Windows/10

File hashes

Hashes for q2numfmt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fa6009832d4ef91a669da107cc71b28b69d368d4eb9018ca18aa34cbaed7cdd
MD5 adc129a158d7c15b288942e7c6c57e5f
BLAKE2b-256 b6fb42df6a747858b956c0c5933c7b206b9a24f0281f584b0cb94581f4edfdb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page