Skip to content

Commit

Permalink
docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Subachev committed Mar 16, 2023
1 parent 3a4a384 commit cefb38e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 22 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rusnum
# rusnum
[![Go Reference](https://pkg.go.dev/badge/github.com/solsw/rusnum.svg)](https://pkg.go.dev/github.com/solsw/rusnum)
====

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

See [examples](https://pkg.go.dev/github.com/solsw/rusnum#pkg-examples) for quickstart usage.
12 changes: 7 additions & 5 deletions floatInWords.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ var (
)

// 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).
// 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]).
func FloatInWords(f float64, frac Fraction, binder Binder, zeroInt, zeroFrac, withZeros bool) string {
if frac < NoFraction || frac > Tenmilliardth {
frac = Hundredmilliardth
Expand Down Expand Up @@ -65,12 +66,13 @@ func FloatInWords(f float64, frac Fraction, binder Binder, zeroInt, zeroFrac, wi
return sb.String()
}

// FloatInWordsAuto is like FloatInWords but determines the Fraction automatically.
// FloatInWordsAuto is like [FloatInWords] but determines the [Fraction] automatically.
func FloatInWordsAuto(f float64, binder Binder, zeroInt, zeroFrac, withZeros bool) string {
return FloatInWords(f, fractionFromFloat(f), binder, zeroInt, zeroFrac, withZeros)
}

// FloatInFractions returns 'f' expressed in 'frac's in russian words.
// FloatInFractions returns 'f' expressed in 'fracs' in russian words.
//
// If result is 0 and 'showZero' is false, empty string is returned.
func FloatInFractions(f float64, frac Fraction, showZero bool) string {
if frac == NoFraction {
Expand All @@ -91,7 +93,7 @@ func FloatInFractions(f float64, frac Fraction, showZero bool) string {
return r
}

// FloatInFractionsAuto is like FloatInFractions but determines the Fraction automatically.
// FloatInFractionsAuto is like [FloatInFractions] but determines the [Fraction] automatically.
func FloatInFractionsAuto(f float64, showZero bool) string {
return FloatInFractions(f, fractionFromFloat(f), showZero)
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/solsw/rusnum
go 1.18

require (
github.com/solsw/mathhelper v0.0.1
github.com/solsw/slicehelper v0.1.1
github.com/solsw/stringhelper v0.1.0
github.com/solsw/mathhelper v0.1.0
github.com/solsw/slicehelper v0.1.2
github.com/solsw/stringhelper v0.3.1
)

require golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 // indirect
require golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/solsw/mathhelper v0.0.1 h1:ER03AbyadT1KPU0+StErxFY5zsdo88DUE2rfwlMdF4A=
github.com/solsw/mathhelper v0.0.1/go.mod h1:v/kAlUjZktXEgexkU6Rewch2VymTZej5leBAXG+2484=
github.com/solsw/slicehelper v0.1.1 h1:JGJh8z9ml/gxeTPo9By0QCQ/rqaAzQnU1FdIQDutjKg=
github.com/solsw/slicehelper v0.1.1/go.mod h1:g2uyHCxszyr8S3lHTIeOYgZjiTtwcU3i+KTP6r+LfpE=
github.com/solsw/stringhelper v0.1.0 h1:cwYMXsrlunOy+cf+N1sIE+etXyK9AjrH2dCqKXc2Hig=
github.com/solsw/stringhelper v0.1.0/go.mod h1:IBtailCUlt8XTM1qfFlwf5ZnBSh78I0M/MQpJg+a6n8=
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 h1:Jvc7gsqn21cJHCmAWx0LiimpP18LZmUxkT5Mp7EZ1mI=
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
github.com/solsw/mathhelper v0.1.0 h1:whq/z0Wihv/RmcrqQ6MVYmvKpyJloO8kzdj3zkhp/Uo=
github.com/solsw/mathhelper v0.1.0/go.mod h1:dSSS7JXR+PM1y2XFYhuT5rK+wjznJv7Ysq+Ka9FTQsE=
github.com/solsw/slicehelper v0.1.2 h1:6wQ5Z+uB8jwMnTB8kmFy/4LrTFLpmS3wxduaubOuY0k=
github.com/solsw/slicehelper v0.1.2/go.mod h1:g2uyHCxszyr8S3lHTIeOYgZjiTtwcU3i+KTP6r+LfpE=
github.com/solsw/stringhelper v0.3.1 h1:9M0rsHzSOtVDzC+0JNIEqSB7yOqqbv4py31KbPerJXw=
github.com/solsw/stringhelper v0.3.1/go.mod h1:IBtailCUlt8XTM1qfFlwf5ZnBSh78I0M/MQpJg+a6n8=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
1 change: 1 addition & 0 deletions intInWords.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
)

// 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.
func IntInWords(n int64, withZeros bool, gender GrammaticalGender) string {
Expand Down
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func getNumeralNumberCase(n int64) numeralNumberCase {
}

// IntAndItems returns string containing 'n' and 'items'.
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func IntAndItems(n int64, showZero bool, items string) string {
if n == 0 && !showZero {
Expand All @@ -70,6 +71,7 @@ func IntAndItems(n int64, showZero bool, 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.
func IntInWordsAndItems(n int64, showZero, withZeros bool, gender GrammaticalGender, items string) string {
Expand Down
4 changes: 4 additions & 0 deletions money.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ func Rubles(n int64) string {
}

// NRubles returns string containing 'n' and corresponding russian for "ruble".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NRubles(n int64, showZero bool) string {
return IntAndItems(n, showZero, Rubles(n))
}

// 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.
func NInWordsRubles(n int64, showZero, withZeros bool) string {
Expand All @@ -29,12 +31,14 @@ func Kopecks(n int64) string {
}

// NKopecks returns string containing 'n' and corresponding russian for "kopeck".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NKopecks(n int64, showZero bool) string {
return IntAndItems(n, showZero, Kopecks(n))
}

// 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 NInWordsKopecks(n int64, showZero, withZeros bool) string {
Expand Down
11 changes: 9 additions & 2 deletions numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func Thousands(n int64) string {
}

// NThousands returns string containing 'n' and corresponding russian for "thousand".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NThousands(n int64, showZero bool) string {
return IntAndItems(n, showZero, Thousands(n))
Expand All @@ -26,6 +27,7 @@ func Millions(n int64) string {
}

// NMillions returns string containing 'n' and corresponding russian for "million".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMillions(n int64, showZero bool) string {
return IntAndItems(n, showZero, Millions(n))
Expand All @@ -37,19 +39,21 @@ func Milliards(n int64) string {
}

// NMilliards returns string containing 'n' and corresponding russian for "milliard".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMilliards(n int64, showZero bool) string {
return IntAndItems(n, showZero, Milliards(n))
}

// Billions returns russian for "milliard" corresponding to 'n'.
// (There is no "billion" in russian.)
// ("billion" is called "milliard" in russian.)
func Billions(n int64) string {
return Milliards(n)
}

// NBillions returns string containing 'n' and corresponding russian for "milliard".
// (There is no "billion" in russian.)
// ("billion" is called "milliard" in russian.)
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NBillions(n int64, showZero bool) string {
return IntAndItems(n, showZero, Billions(n))
Expand All @@ -61,6 +65,7 @@ func Trillions(n int64) string {
}

// NTrillions returns string containing 'n' and corresponding russian for "trillion".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NTrillions(n int64, showZero bool) string {
return IntAndItems(n, showZero, Trillions(n))
Expand All @@ -72,6 +77,7 @@ func Quadrillions(n int64) string {
}

// NQuadrillions returns string containing 'n' and corresponding russian for "quadrillion".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NQuadrillions(n int64, showZero bool) string {
return IntAndItems(n, showZero, Quadrillions(n))
Expand All @@ -83,6 +89,7 @@ func Quintillions(n int64) string {
}

// NQuintillions returns string containing 'n' and corresponding russian for "quintillion".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NQuintillions(n int64, showZero bool) string {
return IntAndItems(n, showZero, Quintillions(n))
Expand Down
22 changes: 22 additions & 0 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ func Centuries(n int64) string {
}

// NCenturies returns string containing 'n' and corresponding russian for "century".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NCenturies(n int64, showZero bool) string {
return IntAndItems(n, showZero, Centuries(n))
}

// 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 NInWordsCenturies(n int64, showZero, withZeros bool) string {
Expand All @@ -38,12 +40,14 @@ func Years(n int64) string {
}

// NYears returns string containing 'n' and corresponding russian for "year".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NYears(n int64, showZero bool) string {
return IntAndItems(n, showZero, Years(n))
}

// 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 NInWordsYears(n int64, showZero, withZeros bool) string {
Expand All @@ -56,12 +60,14 @@ func Months(n int64) string {
}

// NMonths returns string containing 'n' and corresponding russian for "month".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMonths(n int64, showZero bool) string {
return IntAndItems(n, showZero, Months(n))
}

// 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 NInWordsMonths(n int64, showZero, withZeros bool) string {
Expand All @@ -74,12 +80,14 @@ func Weeks(n int64) string {
}

// NWeeks returns string containing 'n' and corresponding russian for "week".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NWeeks(n int64, showZero bool) string {
return IntAndItems(n, showZero, Weeks(n))
}

// 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 NInWordsWeeks(n int64, showZero, withZeros bool) string {
Expand All @@ -92,12 +100,14 @@ func Days(n int64) string {
}

// NDays returns string containing 'n' and corresponding russian for "day".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NDays(n int64, showZero bool) string {
return IntAndItems(n, showZero, Days(n))
}

// 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 NInWordsDays(n int64, showZero, withZeros bool) string {
Expand All @@ -110,12 +120,14 @@ func Hours(n int64) string {
}

// NHours returns string containing 'n' and corresponding russian for "hour".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NHours(n int64, showZero bool) string {
return IntAndItems(n, showZero, Hours(n))
}

// 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 NInWordsHours(n int64, showZero, withZeros bool) string {
Expand All @@ -128,12 +140,14 @@ func Minutes(n int64) string {
}

// NMinutes returns string containing 'n' and corresponding russian for "minute".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMinutes(n int64, showZero bool) string {
return IntAndItems(n, showZero, Minutes(n))
}

// 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 NInWordsMinutes(n int64, showZero, withZeros bool) string {
Expand All @@ -146,12 +160,14 @@ func Seconds(n int64) string {
}

// NSeconds returns string containing 'n' and corresponding russian for "second".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NSeconds(n int64, showZero bool) string {
return IntAndItems(n, showZero, Seconds(n))
}

// 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 NInWordsSeconds(n int64, showZero, withZeros bool) string {
Expand All @@ -164,12 +180,14 @@ func Milliseconds(n int64) string {
}

// NMilliseconds returns string containing 'n' and corresponding russian for "millisecond".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMilliseconds(n int64, showZero bool) string {
return IntAndItems(n, showZero, Milliseconds(n))
}

// 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 NInWordsMilliseconds(n int64, showZero, withZeros bool) string {
Expand All @@ -182,12 +200,14 @@ func Microseconds(n int64) string {
}

// NMicroseconds returns string containing 'n' and corresponding russian for "microsecond".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NMicroseconds(n int64, showZero bool) string {
return IntAndItems(n, showZero, Microseconds(n))
}

// 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 NInWordsMicroseconds(n int64, showZero, withZeros bool) string {
Expand All @@ -200,12 +220,14 @@ func Nanoseconds(n int64) string {
}

// NNanoseconds returns string containing 'n' and corresponding russian for "nanosecond".
//
// If 'n' is 0 and 'showZero' is false, empty string is returned.
func NNanoseconds(n int64, showZero bool) string {
return IntAndItems(n, showZero, Nanoseconds(n))
}

// 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 NInWordsNanoseconds(n int64, showZero, withZeros bool) string {
Expand Down
1 change: 1 addition & 0 deletions tripleInWords.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

// 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 OnesInWords(n int64, gender GrammaticalGender) string {
absN := mathhelper.Abs(n)
Expand Down

0 comments on commit cefb38e

Please sign in to comment.