rusnum

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 7 Imported by: 0

README

rusnum

Go Reference

Package rusnum contains functions to represent numbers and numerical quantities in russian words.

See examples for quickstart usage.

Documentation

Overview

Package rusnum contains functions to represent numbers and numerical quantities in russian words.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Billions

func Billions(n int64) string

Billions returns russian for "milliard" corresponding to 'n'. ("billion" is called "milliard" in russian.)

func Centuries

func Centuries(n int64) string

Centuries returns russian for "century" corresponding to 'n'.

func Days

func Days(n int64) string

Days returns russian for "day" corresponding to 'n'.

func FloatInFractions added in v0.4.0

func FloatInFractions(f float64, frac Fraction, showZero bool) string

FloatInFractions returns 'f' expressed in 'fracs' in russian words. If result is 0 and 'showZero' is false, empty string is returned.

Example
fmt.Println(FloatInFractions(21, Tenth, false))
fmt.Println(FloatInFractions(math.Ln2, Tenmilliardth, false))
Output:

двести десять десятых
шесть миллиардов девятьсот тридцать один миллион четыреста семьдесят одна тысяча восемьсот пять десятимиллиардных

func FloatInFractionsAuto added in v0.4.0

func FloatInFractionsAuto(f float64, showZero bool) string

FloatInFractionsAuto is like FloatInFractions but determines the Fraction automatically.

Example
fmt.Println(FloatInFractionsAuto(21, false))
fmt.Println(FloatInFractionsAuto(12.34, false))
fmt.Println(FloatInFractionsAuto(0.123456789, false))
fmt.Println(FloatInFractionsAuto(math.Log10E, false))
Output:

двадцать один
одна тысяча двести тридцать четыре сотых
сто двадцать три миллиона четыреста пятьдесят шесть тысяч семьсот восемьдесят девять миллиардных
сорок три миллиарда четыреста двадцать девять миллионов четыреста сорок восемь тысяч сто девянoсто стомиллиардных

func FloatInWords

func FloatInWords(f float64, frac Fraction, binder Binder, zeroInt, zeroFrac, withZeros bool) string

FloatInWords returns 'f' in russian words. If f's integer part is 0 and 'zeroInt' is false, no integer part is returned. If f's fractional part is 0 and 'zeroFrac' is false, no fractional part is returned (see FloatInFractions). 'withZeros' is used by f's integer part (see IntInWords).

Example
fmt.Println(FloatInWords(21, Tenth, Whole, false, true, false))
fmt.Println(FloatInWords(math.E, Hundredth, NoBinder, false, true, false))
fmt.Println(FloatInWords(math.E, Thousandth, And, false, true, false))
fmt.Println(FloatInWords(math.E, Millionth, Whole, false, true, false))
Output:

двадцать одна целая ноль десятых
два семьдесят одна сотая
два и семьсот восемнадцать тысячных
две целых семьсот восемнадцать тысяч двести восемьдесят одна миллионная

func FloatInWordsAuto added in v0.3.0

func FloatInWordsAuto(f float64, binder Binder, zeroInt, zeroFrac, withZeros bool) string

FloatInWordsAuto is like FloatInWords but determines the Fraction automatically.

Example
fmt.Println(FloatInWordsAuto(21, Whole, false, false, false))
fmt.Println(FloatInWordsAuto(math.Pi, Whole, false, false, false))
Output:

двадцать одна целая
три целых четырнадцать миллиардов сто пятьдесят девять миллионов двести шестьдесят пять тысяч триста пятьдесят восемь стомиллиардных

func Hours

func Hours(n int64) string

Hours returns russian for "hour" corresponding to 'n'.

func IntAndItems

func IntAndItems(n int64, showZero bool, items string) string

IntAndItems returns string containing 'n' and 'items'. If 'n' is 0 and 'showZero' is false, empty string is returned.

func IntInWords

func IntInWords(n int64, withZeros bool, gender GrammaticalGender) string

IntInWords returns 'n' in russian words. If 'withZeros' is false, zero triples are omitted. 'gender' determines russian grammatical gender for ones of numbers ending in 1 or 2.

Example
fmt.Println(IntInWords(21, true, Neuter))
fmt.Println(IntInWords(-1032, true, Feminine))
fmt.Println(IntInWords(2000001, true, Feminine))
fmt.Println(IntInWords(2000000001, false, Masculine))
Output:

двадцать одно
минус одна тысяча тридцать две
два миллиона ноль тысяч одна
два миллиарда один

func IntInWordsAndItems

func IntInWordsAndItems(n int64, showZero, withZeros bool, gender GrammaticalGender, items string) string

IntInWordsAndItems returns string containing 'n' in russian words and 'items'. If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

Example
fmt.Println(IntInWordsAndItems(2, false, false, Masculine, "кирпича"))
Output:

два кирпича

func Kopecks

func Kopecks(n int64) string

Kopecks returns russian for "kopeck" corresponding to 'n'.

func Microseconds

func Microseconds(n int64) string

Microseconds returns russian for "microsecond" corresponding to 'n'.

func Milliards

func Milliards(n int64) string

Milliards returns russian for "milliard" corresponding to 'n'.

func MilliardsInWords added in v0.6.1

func MilliardsInWords(n int64) string

MilliardsInWords returns milliards (next three digits after millions) of 'n' in russian words.

func Millions

func Millions(n int64) string

Millions returns russian for "million" corresponding to 'n'.

func MillionsInWords added in v0.6.1

func MillionsInWords(n int64) string

MillionsInWords returns millions (next three digits after thousands) of 'n' in russian words.

func Milliseconds

func Milliseconds(n int64) string

Milliseconds returns russian for "millisecond" corresponding to 'n'.

func Minutes

func Minutes(n int64) string

Minutes returns russian for "minute" corresponding to 'n'.

func Months

func Months(n int64) string

Months returns russian for "month" corresponding to 'n'.

func NBillions

func NBillions(n int64, showZero bool) string

NBillions returns string containing 'n' and corresponding russian for "milliard". ("billion" is called "milliard" in russian.) If 'n' is 0 and 'showZero' is false, empty string is returned.

func NCenturies

func NCenturies(n int64, showZero bool) string

NCenturies returns string containing 'n' and corresponding russian for "century". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NDays

func NDays(n int64, showZero bool) string

NDays returns string containing 'n' and corresponding russian for "day". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NHours

func NHours(n int64, showZero bool) string

NHours returns string containing 'n' and corresponding russian for "hour". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NInWordsCenturies

func NInWordsCenturies(n int64, showZero, withZeros bool) string

NInWordsCenturies returns string containing 'n' in russian words and corresponding russian for "century". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsDays

func NInWordsDays(n int64, showZero, withZeros bool) string

NInWordsDays returns string containing 'n' in russian words and corresponding russian for "day". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsHours

func NInWordsHours(n int64, showZero, withZeros bool) string

NInWordsHours returns string containing 'n' in russian words and corresponding russian for "hour". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsKopecks

func NInWordsKopecks(n int64, showZero, withZeros bool) string

NInWordsKopecks returns string containing 'n' in russian words and corresponding russian for "kopeck". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsMicroseconds

func NInWordsMicroseconds(n int64, showZero, withZeros bool) string

NInWordsMicroseconds returns string containing 'n' in russian words and corresponding russian for "microsecond". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsMilliseconds

func NInWordsMilliseconds(n int64, showZero, withZeros bool) string

NInWordsMilliseconds returns string containing 'n' in russian words and corresponding russian for "millisecond". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsMinutes

func NInWordsMinutes(n int64, showZero, withZeros bool) string

NInWordsMinutes returns string containing 'n' in russian words and corresponding russian for "minute". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsMonths

func NInWordsMonths(n int64, showZero, withZeros bool) string

NInWordsMonths returns string containing 'n' in russian words and corresponding russian for "month". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsNanoseconds

func NInWordsNanoseconds(n int64, showZero, withZeros bool) string

NInWordsNanoseconds returns string containing 'n' in russian words and corresponding russian for "nanosecond". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsRubles

func NInWordsRubles(n int64, showZero, withZeros bool) string

NInWordsRubles returns string containing 'n' in russian words and corresponding russian for "ruble". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

Example
fmt.Println(NInWordsRubles(2, false, false))
fmt.Println(NInWordsRubles(2000001, false, true))
Output:

два рубля
два миллиона ноль тысяч один рубль

func NInWordsSeconds

func NInWordsSeconds(n int64, showZero, withZeros bool) string

NInWordsSeconds returns string containing 'n' in russian words and corresponding russian for "second". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsWeeks

func NInWordsWeeks(n int64, showZero, withZeros bool) string

NInWordsWeeks returns string containing 'n' in russian words and corresponding russian for "week". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NInWordsYears

func NInWordsYears(n int64, showZero, withZeros bool) string

NInWordsYears returns string containing 'n' in russian words and corresponding russian for "year". If 'n' is 0 and 'showZero' is false, empty string is returned. If 'withZeros' is false, zero triples are omitted.

func NKopecks

func NKopecks(n int64, showZero bool) string

NKopecks returns string containing 'n' and corresponding russian for "kopeck". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMicroseconds

func NMicroseconds(n int64, showZero bool) string

NMicroseconds returns string containing 'n' and corresponding russian for "microsecond". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMilliards

func NMilliards(n int64, showZero bool) string

NMilliards returns string containing 'n' and corresponding russian for "milliard". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMillions

func NMillions(n int64, showZero bool) string

NMillions returns string containing 'n' and corresponding russian for "million". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMilliseconds

func NMilliseconds(n int64, showZero bool) string

NMilliseconds returns string containing 'n' and corresponding russian for "millisecond". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMinutes

func NMinutes(n int64, showZero bool) string

NMinutes returns string containing 'n' and corresponding russian for "minute". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NMonths

func NMonths(n int64, showZero bool) string

NMonths returns string containing 'n' and corresponding russian for "month". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NNanoseconds

func NNanoseconds(n int64, showZero bool) string

NNanoseconds returns string containing 'n' and corresponding russian for "nanosecond". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NQuadrillions

func NQuadrillions(n int64, showZero bool) string

NQuadrillions returns string containing 'n' and corresponding russian for "quadrillion". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NQuintillions

func NQuintillions(n int64, showZero bool) string

NQuintillions returns string containing 'n' and corresponding russian for "quintillion". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NRubles

func NRubles(n int64, showZero bool) string

NRubles returns string containing 'n' and corresponding russian for "ruble". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NSeconds

func NSeconds(n int64, showZero bool) string

NSeconds returns string containing 'n' and corresponding russian for "second". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NThousands

func NThousands(n int64, showZero bool) string

NThousands returns string containing 'n' and corresponding russian for "thousand". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NTrillions

func NTrillions(n int64, showZero bool) string

NTrillions returns string containing 'n' and corresponding russian for "trillion". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NWeeks

func NWeeks(n int64, showZero bool) string

NWeeks returns string containing 'n' and corresponding russian for "week". If 'n' is 0 and 'showZero' is false, empty string is returned.

func NYears

func NYears(n int64, showZero bool) string

NYears returns string containing 'n' and corresponding russian for "year". If 'n' is 0 and 'showZero' is false, empty string is returned.

func Nanoseconds

func Nanoseconds(n int64) string

Nanoseconds returns russian for "nanosecond" corresponding to 'n'.

func OnesInWords added in v0.6.1

func OnesInWords(n int64, gender GrammaticalGender) string

OnesInWords returns ones (three lower digits) of 'n' in russian words. 'gender' determines russian grammatical gender for ones of numbers ending in 1 or 2.

func Quadrillions

func Quadrillions(n int64) string

Quadrillions returns russian for "quadrillion" corresponding to 'n'.

func QuadrillionsInWords added in v0.6.1

func QuadrillionsInWords(n int64) string

QuadrillionsInWords returns quadrillions (next three digits after trillions) of 'n' in russian words.

func Quintillions

func Quintillions(n int64) string

Quintillions returns russian for "quintillion" corresponding to 'n'.

func QuintillionsInWords added in v0.6.1

func QuintillionsInWords(n int64) string

QuintillionsInWords returns quintillions (next three digits after quadrillions) of 'n' in russian words.

func Rubles

func Rubles(n int64) string

Rubles returns russian for "ruble" corresponding to 'n'.

func Seconds

func Seconds(n int64) string

Seconds returns russian for "second" corresponding to 'n'.

func Thousands

func Thousands(n int64) string

Thousands returns russian for "thousand" corresponding to 'n'.

func ThousandsInWords added in v0.6.1

func ThousandsInWords(n int64) string

ThousandsInWords returns thousands (next three digits after ones) of 'n' in russian words.

func Trillions

func Trillions(n int64) string

Trillions returns russian for "trillion" corresponding to 'n'.

func TrillionsInWords added in v0.6.1

func TrillionsInWords(n int64) string

TrillionsInWords returns trillions (next three digits after milliards) of 'n' in russian words.

func Weeks

func Weeks(n int64) string

Weeks returns russian for "week" corresponding to 'n'.

func Years

func Years(n int64) string

Years returns russian for "year" corresponding to 'n'.

Types

type Binder

type Binder int

Binder of integer and fractional parts.

const (
	NoBinder Binder = iota
	// And separates integer and fractional parts with russian for 'and'.
	And
	// Whole separates integer and fractional parts with russian for 'whole'.
	Whole
)

type Fraction

type Fraction int

Fraction of a whole number.

const (
	NoFraction Fraction = iota
	Tenth
	Hundredth
	Thousandth
	Tenthousandth
	Hundredthousandth
	Millionth
	Tenmillionth
	Hundredmillionth
	Milliardth
	Tenmilliardth
	Hundredmilliardth
)

Supported fractions.

type GrammaticalGender

type GrammaticalGender int

GrammaticalGender - russian grammatical gender.

const (
	// Neuter grammatical gender.
	Neuter GrammaticalGender = iota
	// Masculine grammatical gender.
	Masculine
	// Feminine grammatical gender.
	Feminine
)

Jump to

Keyboard shortcuts

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