Skip to main content

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
1234.59 ####.# 1234.6
[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.

Metadata

Release files for q2numfmt 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for q2numfmt 0.1.1
File Size Uploaded
q2numfmt-0.1.1.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for q2numfmt 0.1.1
File Interpreter ABI Platform
q2numfmt-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / q2numfmt-0.1.1.tar.gz

Download URL q2numfmt-0.1.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d2e030c94e137b01de6d6e6a5763ec911fb6f18601890267f7c4a8d7f4bef0cd
BLAKE2b-256 checksum
How to use checksums
9d8a878814a513b98a077d7b728abe01e55118738f7cc98a7f922db9e4a6e4c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.11.7 Windows/10

Release files / q2numfmt-0.1.1-py3-none-any.whl

Download URL q2numfmt-0.1.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0b3f7ecf13f134d8cf947d33577ddf56d9305f9d0b806e8fa77520818c64e68
BLAKE2b-256 checksum
How to use checksums
811257f176e62bf5b23115c80f3623e7da45ab82a47e1783b0e40c0468ee489f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.11.7 Windows/10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page