thinkeridea / go-extend

go语言扩展包,收集一些常用的操作函数,辅助更快的完成开发工作,并减少重复代码
https://pkg.go.dev/github.com/thinkeridea/go-extend
MIT License
1.34k stars 160 forks source link

BUG: Round(169543.34596, -5) == 199999.99999999997, want 200000 #14

Closed ghost closed 3 years ago

ghost commented 3 years ago

RT

thinkeridea commented 3 years ago

This is indeed a difference in accuracy, I continue to look for other algorithms to ensure his results.

package main

import (
    "fmt"

    "github.com/thinkeridea/go-extend/exmath"
)

func main() {
    fmt.Println(exmath.Round(169543.34596, -5) == 200000.0) // false
    fmt.Printf("%f\n", exmath.Round(169543.34596, -5))      // 200000.000000
    fmt.Println(exmath.Round(169543.34596, -5))             // 199999.99999999997
}
thinkeridea commented 3 years ago

@He11oLx 该问题在 #15 中进行修复,针对 precision 采用不同的算法。

如未报告其它类似问题,该问题将在一周后关闭。