Skip to content

Anuar-boop/num-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

num-format

Python License: MIT No Dependencies

A comprehensive number formatting and conversion tool. Convert between bases, format byte sizes, currencies, percentages, scientific notation, Roman numerals, ordinal numbers, and English words.

Zero external dependencies -- uses only the Python standard library.


Features

  • Base Conversion -- decimal, hex, octal, binary with auto-detection
  • Byte Formatting -- IEC (KiB/MiB/GiB) and SI (KB/MB/GB) with all unit breakdowns
  • Currency Formatting -- 17 currencies with proper locale conventions (USD, EUR, GBP, JPY, MYR, BTC, and more)
  • Percentage -- format, ratio, fraction, and reciprocal views
  • Scientific Notation -- standard, engineering, and SI prefix formats
  • Roman Numerals -- convert to/from Roman numerals (1-3999) with breakdown
  • Ordinal Numbers -- 1st, 2nd, 3rd, 4th, etc.
  • Number Words -- "one hundred twenty-three" (supports up to decillions)
  • Padding/Alignment -- right, left, center, zero-padded, custom fill characters
  • Digit Grouping -- configurable separator and group size
  • Stdin Support -- pipe numbers from other commands

Installation

No installation needed. Just download and run:

curl -O https://raw.githubusercontent.com/Anuar-boop/num-format/main/num_format.py
chmod +x num_format.py

Or clone the repository:

git clone https://github.com/Anuar-boop/num-format.git
cd num-format

Usage

Full Summary (Default)

python3 num_format.py 255

Output:

  NUMBER ANALYSIS: 255
==================================================

  Base Conversions:
----------------------------------------
  Decimal:  255
  Hex:      0xff  (0xFF)
  Octal:    0o377
  Binary:   0b11111111
  Bits:     8

  Grouped:      255
  Ordinal:      255th
  Roman:        CCLV
  Words:        two hundred fifty-five

  Formatting:
----------------------------------------
  Comma:        255
  Scientific:   2.55e+02
  Engineering:  255.000e+0
  SI Prefix:    255.000
  Percentage:   255.00%

  Byte Interpretation:
----------------------------------------
  IEC:          255 B
  SI:           255 B

  Currency:
----------------------------------------
  BTC:  ₿255.00000000
  EUR:  255,00 €
  GBP:  £255.00
  JPY:  ¥255
  MYR:  RM255.00
  USD:  $255.00

Base Conversions

python3 num_format.py --bases 255
python3 num_format.py --bases 0xFF      # from hex
python3 num_format.py --bases 0b11111111 # from binary
python3 num_format.py --bases 0o377      # from octal

Byte Size Formatting

python3 num_format.py --bytes 1073741824
  Input:    1,073,741,824 bytes
  IEC:      1.00 GiB
  SI:       1.07 GB

  All IEC units:
    1,073,741,824 B
       1,048,576.0000 KiB
           1,024.0000 MiB
               1.0000 GiB
  ...

Currency Formatting

python3 num_format.py --currency USD 1234.56
python3 num_format.py --currency EUR 1234.56
python3 num_format.py --currency BTC 0.05
  Amount:     1234.56
  Formatted:  $1,234.56

  All currencies:
    AUD: A$1,234.56
    BRL: R$1.234,56
    BTC: ₿1,234.56000000
    ...

Roman Numerals

python3 num_format.py --roman 2024
python3 num_format.py --roman MCMXCIX  # from Roman to decimal
  Decimal:  2024
  Roman:    MMXXIV
  Breakdown: M=1000 x2, X=10 x2, IV=4 x1

Number Words

python3 num_format.py --words 123456789
  one hundred twenty-three million four hundred fifty-six thousand seven hundred eighty-nine

Scientific Notation

python3 num_format.py --scientific 6.022e23
  Value:         6.022e+23
  Scientific:    6.0220e+23
  Engineering:   602.200e+21
  SI Prefix:     602.200 Y
  Log10:         23.7797
  Log2:          79.0010
  Ln:            54.7979

Ordinal Numbers

python3 num_format.py --ordinal 42
  42nd

Percentage

python3 num_format.py --percentage 75
  Value:          75
  As percentage:  75.00%
  As ratio:       0.7500
  As fraction:    75/100
  Reciprocal:     1 in 1.3

Padding

python3 num_format.py --padding 20 42
  Right-aligned:   [                  42]
  Left-aligned:    [42                  ]
  Center-aligned:  [         42         ]
  Zero-padded:     [00000000000000000042]

Pipe from Stdin

echo 1048576 | python3 num_format.py --bytes
wc -c file.txt | python3 num_format.py --bytes

CLI Reference

Flag Description
--bases Show base conversions (dec/hex/oct/bin)
--bytes Format as byte size
--byte-system {iec,si} Byte system: iec (1024) or si (1000)
--currency CODE Format as currency (USD, EUR, GBP, etc.)
--percentage Format as percentage
--scientific Scientific/engineering notation
--roman Convert to/from Roman numerals
--ordinal Format as ordinal (1st, 2nd, 3rd)
--words Convert to English words
--padding WIDTH Show with various padding styles
--precision N Decimal precision (default: 2)
--version Show version

Supported Currencies

Code Symbol Locale
USD $ US Dollar
EUR EUR Euro
GBP GBP British Pound
JPY JPY Japanese Yen
CNY CNY Chinese Yuan
MYR RM Malaysian Ringgit
SGD S$ Singapore Dollar
AUD A$ Australian Dollar
CAD C$ Canadian Dollar
INR INR Indian Rupee
BRL R$ Brazilian Real
CHF CHF Swiss Franc
BTC BTC Bitcoin
KRW KRW South Korean Won
RUB RUB Russian Ruble
TRY TRY Turkish Lira
MXN $ Mexican Peso

License

MIT -- Copyright (c) 2026 Anuar AX

About

Number formatting and conversion tool. Base conversion, byte sizes, currencies, Roman numerals, ordinals, number words, scientific notation. Zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages