This commit is contained in:
robinson
2019-10-07 15:08:41 +02:00
parent 339410327c
commit cdd9e15a66
2 changed files with 67 additions and 55 deletions

View File

@ -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
}