num2words

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 4 Imported by: 36 modules, 29 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

num2words

GoDoc

num2words - Numbers to words converter in Go (Golang)

Usage

First, import package num2words

import github.com/divan/num2words

Convert number

  str := num2words.Convert(17) // outputs "seventeen"
  ...
  str := num2words.Convert(1024) // outputs "one thousand twenty four"
  ...
  str := num2words.Convert(-123) // outputs "minus one hundred twenty three"

Convert number with " and " between number groups:

  str := num2words.ConvertAnd(514) // outputs "five hundred and fourteen"
  ...
  str := num2words.ConvertAnd(123) // outputs "one hundred and twenty three"

Language Support

Ukrainian language support with gender agreement and noun forms:

  str, _ := num2words.ConvertLang(42, "uk") // outputs "сорок два"
  str, _ := num2words.ConvertLang(42, "en") // outputs "forty-two"

Direct Ukrainian API with advanced features:

  import "github.com/divan/num2words/lang/ukrainian"
  
  str := ukrainian.Convert(42) // outputs "сорок два"
  
  // Gender agreement (masculine/feminine/neuter)
  str := ukrainian.ConvertWithOptions(1, ukrainian.Options{
    Gender: ukrainian.Feminine,
  }) // outputs "одна"
  
  // With noun forms (automatically handles singular/plural/genitive)
  str := ukrainian.ConvertWithOptions(2, ukrainian.Options{
    Gender: ukrainian.Feminine,
    WithNoun: true,
    NounForms: &ukrainian.NounForms{
      Singular: "гривня",
      NominativePlural: "гривні", 
      GenitivePlural: "гривень",
    },
  }) // outputs "дві гривні"

Documentation

Overview

Package num2words provides language definitions for number-to-words conversion.

Package num2words implements numbers to words converter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(number int) string

Convert converts number into the words representation.

func ConvertAnd

func ConvertAnd(number int) string

ConvertAnd converts number into the words representation with " and " added between number groups.

func ConvertFloat added in v1.0.1

func ConvertFloat(number float64, precision Precision) string

ConvertFloat converts float number into words representation. precision controls decimal places (-1 for automatic precision)

func ConvertFloatAnd added in v1.0.1

func ConvertFloatAnd(number float64, precision Precision) string

ConvertFloatAnd converts float number into words representation with " and " added between number groups. precision controls decimal places (-1 for automatic precision)

func ConvertLang added in v1.0.3

func ConvertLang(number int, lang string) (string, error)

ConvertLang converts number into words for the specified language

func ConvertLangAnd added in v1.0.3

func ConvertLangAnd(number int, lang string) (string, error)

ConvertLangAnd converts number into words with "and" for the specified language

Types

type Case added in v1.0.3

type Case int

Case represents grammatical case for languages that require it

const (
	Nominative Case = iota
	Genitive
	Dative
	Accusative
	Instrumental
	Locative
	Vocative
)

type Gender added in v1.0.3

type Gender int

Gender represents grammatical gender for languages that require it

const (
	Masculine Gender = iota
	Feminine
	Neuter
)

type NounForms added in v1.0.3

type NounForms struct {
	Singular         string // Used with 1: "один день"
	NominativePlural string // Used with 2-4: "два дні"
	GenitivePlural   string // Used with 5+: "п'ять днів"
}

NounForms contains different forms of a noun for proper agreement with numbers

type NounSelector added in v1.0.3

type NounSelector func(count int, gender Gender) string

NounSelector is a function that selects the appropriate noun form based on the number and gender context

type Precision added in v1.0.1

type Precision int

Precision represents the number of decimal places to convert -1 means automatic precision (removes trailing zeros)

const (
	AutoPrecision Precision = -1
)

Directories

Path Synopsis
lang
ukrainian
Package ukrainian contains Ukrainian language data for number conversion.
Package ukrainian contains Ukrainian language data for number conversion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址