- update output
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.4
李光春 2 years ago
parent 98ebadd42c
commit 243be10d14

@ -22,3 +22,10 @@ func (d Decimal) MoneyFloat64() float64 {
f, _ := rat.Float64()
return f
}
// MoneyPoint 输出 float64带小数点
func (d Decimal) MoneyPoint(p int) float64 {
rat, _ := new(big.Rat).SetString(d.floatValue.Text('f', p))
f, _ := rat.Float64()
return f
}

@ -1,8 +1,6 @@
package godecimal
import (
"fmt"
"github.com/shopspring/decimal"
"math/big"
"reflect"
"testing"
@ -55,35 +53,6 @@ func TestOperation(t *testing.T) {
t.Log("a3/a4", a3.Quo(a4), a3.Quo(a4).String(), a3.Quo(a4).Float64(), reflect.TypeOf(a3.Quo(a4).Float64()), a3.Quo(a4).MoneyFloat64(), reflect.TypeOf(a3.Quo(a4).MoneyFloat64()))
}
func TestDecimal1(t *testing.T) {
price, err := decimal.NewFromString("136.02")
if err != nil {
panic(err)
}
quantity := decimal.NewFromInt(3)
fee, _ := decimal.NewFromString(".035")
taxRate, _ := decimal.NewFromString(".08875")
subtotal := price.Mul(quantity)
preTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1)))
total := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1)))
fmt.Println("Subtotal:", subtotal, reflect.TypeOf(subtotal)) // Subtotal: 408.06
fmt.Println("Pre-tax:", preTax, reflect.TypeOf(preTax)) // Pre-tax: 422.3421
fmt.Println("Taxes:", total.Sub(preTax)) // Taxes: 37.482861375
fmt.Println("Total:", total) // Total: 459.824961375
fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875
t.Log(total.String())
t.Log(total.Float64())
t.Log(total.Floor())
}
func Test3(t *testing.T) {
var x1, y1 float64 = 10, 3

@ -1,5 +1,3 @@
module go.dtapp.net/godecimal
go 1.18
require github.com/shopspring/decimal v1.3.1
go 1.19

@ -1,2 +0,0 @@
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

@ -1,3 +1,3 @@
package godecimal
const Version = "1.0.3"
const Version = "1.0.4"

Loading…
Cancel
Save