本文整理汇总了Golang中github.com/shopspring/decimal.NewFromFloat函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFromFloat函数的具体用法?Golang NewFromFloat怎么用?Golang NewFromFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFromFloat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: BenchmarkDoCreateAccount
func BenchmarkDoCreateAccount(b *testing.B) {
for n := 0; n < b.N; n++ {
accountDetail := AccountDetails{
"",
"",
"User,Test",
decimal.NewFromFloat(0.),
decimal.NewFromFloat(0.),
decimal.NewFromFloat(0.),
"cheque",
0,
}
accountHolderDetail := AccountHolderDetails{
"Test",
"User",
"1900-01-01",
"19000101-1000-100",
"555-123-1234",
"",
"[email protected]er.com",
"Address 1",
"Address 2",
"Address 3",
"22202",
}
ti := time.Now()
sqlTime := int32(ti.Unix())
_ = doCreateAccount(sqlTime, &accountDetail, &accountHolderDetail)
_ = doDeleteAccount(&accountDetail)
}
}
开发者ID:BVNK,项目名称:bank,代码行数:33,代码来源:database_test.go
示例2: setAccountDetails
func setAccountDetails(data []string) (accountDetails AccountDetails, err error) {
if len(data) < 15 {
return AccountDetails{}, errors.New("accounts.setAccountDetails: Not all fields required present")
}
if data[4] == "" {
return AccountDetails{}, errors.New("accounts.setAccountDetails: Family name cannot be empty")
}
if data[3] == "" {
return AccountDetails{}, errors.New("accounts.setAccountDetails: Given name cannot be empty")
}
accountDetails.BankNumber = BANK_NUMBER
accountDetails.AccountHolderName = data[4] + "," + data[3] // Family Name, Given Name
accountDetails.AccountBalance = decimal.NewFromFloat(OPENING_BALANCE)
accountDetails.Overdraft = decimal.NewFromFloat(OPENING_OVERDRAFT)
accountDetails.AvailableBalance = decimal.NewFromFloat(OPENING_BALANCE + OPENING_OVERDRAFT)
// Get account type
accountType := data[14]
switch accountType {
case "":
accountType = "cheque" // Default to chequing account
break
case "savings", "cheque", "merchant", "money-market", "cd", "ira", "rcp", "credit", "mortgage", "loan":
// Valid
break
default:
return AccountDetails{}, errors.New("accounts.setAccountDetails: Account type not valid, must be one of savings, cheque, merchant, money-market, cd, ira, rcp, credit, mortgage, loan")
break
}
accountDetails.Type = accountType
return
}
开发者ID:BVNK,项目名称:bank,代码行数:33,代码来源:accounts.go
示例3: Encode
//Encode generates a geozip bucket id for a given latitude and longitude.
//Argument validate is true if a validation is to be performed.
//Precision is a number in the range of [0, 18] such that 0 gives lowest precision (000000000000000000) and 18 gives the most precise bucket id.
func Encode(latitude, longitude float64, validate bool, precision int) int64 {
if validate && !Valid(latitude, longitude) {
return 0
}
latitudeShifted := decimal.NewFromFloat(latitude).Add(decimal.NewFromFloat(90.0))
longitudeShifted := decimal.NewFromFloat(longitude).Add(decimal.NewFromFloat(180.0))
latString := latitudeShifted.String() + ".0"
lonString := longitudeShifted.String() + ".0"
latParts := strings.Split(latString, ".")
lonParts := strings.Split(lonString, ".")
latString = resizeCharacteristic(latParts[0]) + resizeMantissa(latParts[1])
lonString = resizeCharacteristic(lonParts[0]) + resizeMantissa(lonParts[1])
bucketString := zip(latString, lonString)
bucket, err := strconv.ParseInt(bucketString, 10, 64)
if err != nil {
fmt.Errorf("Error parsing zipped string to int64")
}
for i := 0; i < maxPrecision-precision; i++ {
bucket /= 10
}
for i := 0; i < maxPrecision-precision; i++ {
bucket *= 10
}
return bucket
}
开发者ID:nick11roberts,项目名称:geozip,代码行数:28,代码来源:geozip.go
示例4: Money
func Money(value interface{}, code string) (MoneyObject, error) {
currency, found := CurrencyTypes[code]
if !found {
return MoneyObject{}, errors.New("Code not found.")
}
var money decimal.Decimal
var moneyObject MoneyObject
switch v := value.(type) {
case string:
m, err := decimal.NewFromString(v)
if err != nil {
return MoneyObject{}, err
}
money = m
case float32:
money = decimal.NewFromFloat(float64(v))
case float64:
money = decimal.NewFromFloat(v)
case int:
money = decimal.NewFromFloat(float64(v))
default:
return MoneyObject{}, errors.New("Value could not be translated.")
}
moneyObject.money = money
moneyObject.currency = currency
return moneyObject, nil
}
开发者ID:stints,项目名称:gocurrency,代码行数:31,代码来源:currency.go
示例5: TestDoCreateAccount
func TestDoCreateAccount(t *testing.T) {
//accountDetails AccountDetails, accountHolderDetails AccountHolderDetails
accountDetail := AccountDetails{
"",
"",
"User,Test",
decimal.NewFromFloat(0.),
decimal.NewFromFloat(0.),
decimal.NewFromFloat(0.),
0,
}
ti := time.Now()
sqlTime := int32(ti.Unix())
err := doCreateAccount(sqlTime, &accountDetail)
if err != nil {
t.Errorf("DoCreateAccount does not pass. Looking for %v, got %v", nil, err)
}
err = doDeleteAccount(&accountDetail)
if err != nil {
t.Errorf("DoDeleteAccount does not pass. Looking for %v, got %v", nil, err)
}
}
开发者ID:thiesa,项目名称:bank,代码行数:25,代码来源:database_test.go
示例6: Decode
//Decode is the inverse operation of Encode.
//Decode returns latitude, longitude, and whether or not they are both represented precisely as float64 types.
func Decode(bucket int64) (float64, float64, bool) {
var latitudeUnshifted, longitudeUnshifted decimal.Decimal
var latitude, longitude float64
var err error
var exact bool
bucketString := strconv.FormatInt(bucket, 10)
for len(bucketString) < 18 {
bucketString = "0" + bucketString
}
latString, lonString := unzip(bucketString)
latString = latString[0:3] + "." + latString[3:]
lonString = lonString[0:3] + "." + lonString[3:]
latitudeUnshifted, err = decimal.NewFromString(latString)
longitudeUnshifted, err = decimal.NewFromString(lonString)
if err != nil {
fmt.Errorf("Error creating decimal from string")
}
latitudeUnshifted = latitudeUnshifted.Sub(decimal.NewFromFloat(90.0))
longitudeUnshifted = longitudeUnshifted.Sub(decimal.NewFromFloat(180.0))
latitude, exact = latitudeUnshifted.Float64()
longitude, exact = longitudeUnshifted.Float64()
return latitude, longitude, exact
}
开发者ID:nick11roberts,项目名称:geozip,代码行数:27,代码来源:geozip.go
示例7: TestSquareRootOfFour
func TestSquareRootOfFour(t *testing.T) {
four := decimal.NewFromFloat(4.0)
sqrt := Sqrt(four)
if !sqrt.Equals(decimal.NewFromFloat(2.0)) {
t.Fatalf("Square root of %s is %s", four, sqrt)
}
t.Logf("Square root of %s is %s", four, sqrt)
}
开发者ID:fernandosanchezjr,项目名称:gotsp,代码行数:8,代码来源:sqrt_test.go
示例8: BenchmarkAddDecimalWithoutNew
func BenchmarkAddDecimalWithoutNew(b *testing.B) {
decimalStartFloat := decimal.NewFromFloat(StartFloat)
decimalFactor := decimal.NewFromFloat(Factor)
for n := 0; n < b.N; n++ {
AddDecimalWithoutNew(decimalStartFloat, decimalFactor)
}
}
开发者ID:Zumata,项目名称:benchmark,代码行数:8,代码来源:decimal_test.go
示例9: AddDecimal
func AddDecimal() (calculated decimal.Decimal) {
decimalStartFloat := decimal.NewFromFloat(StartFloat)
decimalFactor := decimal.NewFromFloat(Factor)
calculated = decimalStartFloat.Add(decimalFactor)
return
}
开发者ID:Zumata,项目名称:benchmark,代码行数:8,代码来源:decimal.go
示例10: MultiplyDecimal
func MultiplyDecimal() (calculated decimal.Decimal) {
decimalStartFloat := decimal.NewFromFloat(StartFloat)
decimalFactor := decimal.NewFromFloat(Factor)
calculated = decimalStartFloat.Mul(decimalFactor)
return
}
开发者ID:Zumata,项目名称:benchmark,代码行数:8,代码来源:decimal.go
示例11: TestCanWidthdraw
func TestCanWidthdraw(t *testing.T) {
account := CreateAccount(10)
account.Deposit(decimal.NewFromFloat(20))
account.Withdraw(decimal.NewFromFloat(50))
assert.Equal(t, decimal.NewFromFloat(20).String(), account.GetBalance().String())
}
开发者ID:Hinton,项目名称:go-learn,代码行数:9,代码来源:account_test.go
示例12: Sqrt
// Square root using Newton's method
// Shamelessly ripped from https://gist.github.com/marcellodesales/2487009
func Sqrt(x decimal.Decimal) decimal.Decimal {
p := decimal.NewFromFloat(0.0)
z := decimal.NewFromFloat(1.0)
for !p.Sub(z).Equals(ConstMin) {
z = newton(z, x)
p = newton(z, x)
}
return z
}
开发者ID:fernandosanchezjr,项目名称:gotsp,代码行数:11,代码来源:sqrt.go
示例13: TestCalculate
func TestCalculate(t *testing.T) {
irrf := NewIRRF(irrfByYear["2016"])
for _, testCase := range testCases {
irrfDue := irrf.Calculate(decimal.NewFromFloat(testCase.irrfBase))
if irrfDue.Cmp(decimal.NewFromFloat(testCase.irrfDue)) != 0 {
t.Errorf("Expected %v, got %v", testCase.irrfDue, irrfDue)
}
}
}
开发者ID:thiagocaiubi,项目名称:isiro,代码行数:9,代码来源:irrf_test.go
示例14: TestCalculate
func TestCalculate(t *testing.T) {
inss := NewINSS(inssByYear["2016"])
for _, testCase := range testCases {
inssDue := inss.Calculate(decimal.NewFromFloat(testCase.grossSalary))
if inssDue.Cmp(decimal.NewFromFloat(testCase.inssDue)) != 0 {
t.Errorf("Expected %v, got %v", testCase.inssDue, inssDue)
}
}
}
开发者ID:thiagocaiubi,项目名称:isiro,代码行数:9,代码来源:inss_test.go
示例15: setupGrid
func setupGrid() *Grid {
grid := NewGrid(NewCoord(decimal.NewFromFloat(0.0),
decimal.NewFromFloat(0.0)), decimal.NewFromFloat(90.0),
decimal.NewFromFloat(180.0), nil, nil)
grid.Append(coordA)
grid.Append(coordB)
grid.Append(coordC)
grid.Append(coordD)
return grid
}
开发者ID:fernandosanchezjr,项目名称:gotsp,代码行数:10,代码来源:grids_test.go
示例16: TestDeposit
func TestDeposit(t *testing.T) {
account := CreateAccount(10)
assert.Equal(t, account.GetBalance(), decimal.NewFromFloat(0))
account.Deposit(decimal.NewFromFloat(2510.50))
assert.Equal(t, account.GetBalance(), decimal.NewFromFloat(2510.50))
// Attempt to deposit negative value
_, err := account.Deposit(decimal.NewFromFloat(-1))
assert.NotNil(t, err)
}
开发者ID:Hinton,项目名称:go-learn,代码行数:13,代码来源:account_test.go
示例17: BenchmarkSavePainTransaction
func BenchmarkSavePainTransaction(b *testing.B) {
config, _ := configuration.LoadConfig()
SetConfig(&config)
for n := 0; n < b.N; n++ {
sender := AccountHolder{"accountNumSender", "bankNumSender"}
receiver := AccountHolder{"accountNumReceiver", "bankNumReceiver"}
trans := PAINTrans{101, sender, receiver, decimal.NewFromFloat(0.), decimal.NewFromFloat(0.), 10., 10., "Test desc", "approved"}
_ = savePainTransaction(trans)
_ = removePainTransaction(trans)
}
}
开发者ID:BVNK,项目名称:bank,代码行数:13,代码来源:database_test.go
示例18: main
func main() {
rand.Seed(time.Now().UTC().UnixNano())
termChan := make(chan os.Signal, 1)
signal.Notify(termChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
cant := 0
log.Println("Flooding with transactions... =D")
initialDate, _ := time.Parse("2-JAN-06 15:04:05", "1-JAN-14 10:00:00")
for i := 0; i < 5; i++ {
go func() {
for {
id := fmt.Sprintf("%v", rand.Intn(10000))
from := randomdata.Currency()
to := randomdata.Currency()
rate := decimal.NewFromFloat(randomdata.Decimal(1, 2, 2))
sell := decimal.NewFromFloat(randomdata.Decimal(50, 1000, 2))
buy := rate.Mul(sell)
tp := initialDate.Add(time.Hour * 24 * time.Duration(cant)).
Format("2-JAN-06 15:04:05")
oc := randomdata.Country(randomdata.TwoCharCountry)
m := map[string]interface{}{
"userId": id,
"currencyFrom": from,
"currencyTo": to,
"amountSell": sell,
"amountBuy": buy,
"rate": rate,
"timePlaced": tp,
"originatingCountry": oc,
}
mJson, _ := json.Marshal(m)
contentReader := bytes.NewReader(mJson)
req, _ := http.NewRequest("POST", "http://localhost:8080/api/v1/transaction", contentReader)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
client.Do(req)
cant++
time.Sleep(time.Millisecond * time.Duration(3000))
}
}()
}
<-termChan
log.Println("total messages:", cant)
}
开发者ID:ezeql,项目名称:cf-test,代码行数:50,代码来源:flooder.go
示例19: TestSummary
func TestSummary(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
summaryAPI := fmt.Sprintf("/accounts/%d/summary", TestAccountID)
assert.Equal(t, summaryAPI, req.RequestURI)
err := respondWithFixture(w, "summary.json")
require.NoError(t, err)
}))
defer ts.Close()
ar := newClient(ts.URL, "Token", nil).Accounts(TestAccountID)
summary, err := ar.Summary()
require.NoError(t, err)
assert.Equal(t, 1788402, summary.InvestorID)
assert.Equal(t, decimal.NewFromFloat(50.77), summary.AvailableCash)
assert.Equal(t, decimal.NewFromFloat(100.15), summary.AccountTotal)
assert.Equal(t, decimal.NewFromFloat(0.26), summary.AccruedInterest)
assert.Equal(t, decimal.NewFromFloat(0), summary.InFundingBalance)
assert.Equal(t, decimal.NewFromFloat(0.16), summary.ReceivedInterest)
assert.Equal(t, decimal.NewFromFloat(0.62), summary.ReceivedPrincipal)
assert.Equal(t, decimal.NewFromFloat(0), summary.ReceivedLateFees)
assert.Equal(t, decimal.NewFromFloat(49.38), summary.OutstandingPrincipal)
assert.Equal(t, 2, summary.TotalNotes)
assert.Equal(t, 3, summary.TotalPortfolios)
}
开发者ID:Tonkpils,项目名称:lendingclub,代码行数:26,代码来源:accounts_test.go
示例20: orderTests
func orderTests(t *testing.T, order Order) {
// Check that dates are parsed
d := time.Date(2016, time.May, 17, 4, 14, 36, 0, time.UTC)
if !d.Equal(*order.CreatedAt) {
t.Errorf("Order.CreatedAt returned %+v, expected %+v", order.CreatedAt, d)
}
// Check null dates
if order.ProcessedAt != nil {
t.Errorf("Order.ProcessedAt returned %+v, expected %+v", order.ProcessedAt, nil)
}
// Check prices
p := decimal.NewFromFloat(10)
if !p.Equals(*order.TotalPrice) {
t.Errorf("Order.TotalPrice returned %+v, expected %+v", order.TotalPrice, p)
}
// Check null prices, notice that prices are usually not empty.
if order.TotalTax != nil {
t.Errorf("Order.TotalTax returned %+v, expected %+v", order.TotalTax, nil)
}
// Check customer
if order.Customer == nil {
t.Error("Expected Customer to not be nil")
}
if order.Customer.Email != "[email protected]" {
t.Errorf("Customer.Email, expected %v, actual %v", "[email protected]", order.Customer.Email)
}
}
开发者ID:Receiptful,项目名称:go-shopify,代码行数:31,代码来源:order_test.go
注:本文中的github.com/shopspring/decimal.NewFromFloat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论