done
This commit is contained in:
12
slownie.go
12
slownie.go
@ -44,10 +44,10 @@ func toFixed(num float64, precision int) float64 {
|
||||
return float64(round(num*output)) / output
|
||||
}
|
||||
|
||||
func split(value float64) (int64, int32) {
|
||||
func split(value float64) (int64, int64) {
|
||||
pre := int64(value)
|
||||
// post := int32((value - float64(pre)) * 100)
|
||||
post := int32(math.Mod((value*100)+0.5, 100))
|
||||
post := int64((round(value*100) % 100))
|
||||
return pre, post
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func someSlownie(value int64, some []string) string {
|
||||
}
|
||||
|
||||
// KwotaSlownie - return value in words of zloty and groszy
|
||||
func KwotaSlownie(input float64) (output string, err error) {
|
||||
func KwotaSlownie(input float64, numbers bool) (output string, err error) {
|
||||
input = toFixed(input, 2)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -138,5 +138,9 @@ func KwotaSlownie(input float64) (output string, err error) {
|
||||
input = -input
|
||||
}
|
||||
zloty, grosze := split(input)
|
||||
return minusword + someSlownie(zloty, _zlotyWord) + fmt.Sprintf(" %02d/100", grosze), nil
|
||||
if numbers {
|
||||
return minusword + someSlownie(zloty, _zlotyWord) + fmt.Sprintf(" %02d/100", grosze), nil
|
||||
}
|
||||
return minusword + someSlownie(zloty, _zlotyWord) + " " + someSlownie(grosze, _groszyWord), nil
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user