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

math: Round returns an int in a float64 #23496

Closed
Fale opened this issue Jan 21, 2018 · 1 comment
Closed

math: Round returns an int in a float64 #23496

Fale opened this issue Jan 21, 2018 · 1 comment

Comments

@Fale
Copy link

Fale commented Jan 21, 2018

As per documentation, the math.Round "returns the nearest integer" [1]. Why does it return it in a float? [2] Wouldn't make more sense to return it in an integer typed variable?

[1]

// Round returns the nearest integer, rounding half away from zero.

[2]
func Round(x float64) float64 {

@dominikh
Copy link
Member

The output of math.Round is most likely to be used with other functions in the math package, which all operate on floats. math.Floor exists for the same reason. It wouldn't be necessary if it returned int.

In the future, questions like these are best asked on one of the forums, see https://github.com/golang/go/wiki/Questions for more information.

@mikioh mikioh changed the title Round returns an int in a float64 math: Round returns an int in a float64 Jan 26, 2018
@golang golang locked and limited conversation to collaborators Jan 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants