Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split of small negative values doesn't work properly #106

Closed
arzonus opened this issue Apr 4, 2022 · 1 comment
Closed

Split of small negative values doesn't work properly #106

arzonus opened this issue Apr 4, 2022 · 1 comment

Comments

@arzonus
Copy link

arzonus commented Apr 4, 2022

I found that a small negative amount will be split wrongly.

Example

package main

import (
	"fmt"

	"github.com/Rhymond/go-money"
)

func main() {
	var val = money.New(-2, "EUR")
	parts, err := val.Split(3)
	if err != nil {
		fmt.Println(err)
	}

	for _, part := range parts {
		fmt.Println(part.Display())
	}
}

Expected output

-€0.01
-€0.01
-€0.00

Actual output

€0.01
€0.01
€0.00

It seems that if a money value is less than the number of split parts it returns a wrong sign because 0.04/3 returns 0.02,0.01,0.01.

@arzonus arzonus changed the title Negative split of small values doesn't work properly Split of small negative values doesn't work properly Apr 4, 2022
@Rhymond
Copy link
Owner

Rhymond commented Apr 8, 2022

Thanks, Great find! The issue is fixed and released in v1.0.6 release

@Rhymond Rhymond closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants