Skip to content
Amir Iranmanesh edited this page Aug 11, 2026 · 2 revisions

digit

Format numbers with thousands separators and convert digits to Persian words.

import "github.com/amiranmanesh/go-persian-tools/digit"

Digit to words

Accepts Persian or ASCII digits, optionally negative. Returns an empty string on invalid input.

digit.DigitToWord("۱۵۶۷۸۹") // "صد پنجاه و شش هزار هفتصد هشتاد و نه"
digit.DigitToWord("156789") // "صد پنجاه و شش هزار هفتصد هشتاد و نه"
digit.DigitToWord("-10")     // "منفی ده"

Commas

digit.AddCommas(14555478854) // "14,555,478,854"

n, err := digit.RemoveCommas("4,555,478,854") // 4555478854 (int64), nil
if err != nil {
    // input was not a valid integer
}

RemoveCommas returns (int64, error) — it will not overflow on large values and reports parse errors instead of silently returning 0.

Clone this wiki locally