gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/floatx/float_test.go (about)

     1  package floatx
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"testing"
     7  )
     8  
     9  func TestName(t *testing.T) {
    10  	sum := 0.0
    11  
    12  	count := 10
    13  	var list [10]float64
    14  	for i := 0; i < count; i++ {
    15  		r := rand.Float64()
    16  		o := r
    17  		//r = float64(math.Round((r + 0.0000001) * 100000.0))
    18  		//r = r / 100000.0
    19  		list[i] = r
    20  		fmt.Println("r", r, o)
    21  	}
    22  
    23  	for i := 0; i < count; i++ {
    24  		sum += list[i]
    25  	}
    26  
    27  	fmt.Println("sum", sum)
    28  	//EPS2 := 10000.0
    29  	sum = 0.0
    30  	for i := 0; i < count; i++ {
    31  		sum += list[i]
    32  		t := float64(int((sum + 0.0001) * 1000.0))
    33  		sum = t / 1000.0
    34  	}
    35  	fmt.Println("sum2", sum)
    36  }