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.

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.1.tar.gz (8.1 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.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: q2numfmt-0.1.1.tar.gz
  • Upload date:
  • Size: 8.1 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.1.tar.gz
Algorithm Hash digest
SHA256 d2e030c94e137b01de6d6e6a5763ec911fb6f18601890267f7c4a8d7f4bef0cd
MD5 eb32bf5130d4c452d9ae30d123f7c90c
BLAKE2b-256 9d8a878814a513b98a077d7b728abe01e55118738f7cc98a7f922db9e4a6e4c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: q2numfmt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0b3f7ecf13f134d8cf947d33577ddf56d9305f9d0b806e8fa77520818c64e68
MD5 f4827515012e3f07af3c905b25bae6e4
BLAKE2b-256 811257f176e62bf5b23115c80f3623e7da45ab82a47e1783b0e40c0468ee489f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

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