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

get all 0 when gets decimal field value from mysql #1890

Closed
youtwo123 opened this issue May 10, 2018 · 3 comments
Closed

get all 0 when gets decimal field value from mysql #1890

youtwo123 opened this issue May 10, 2018 · 3 comments

Comments

@youtwo123
Copy link

youtwo123 commented May 10, 2018

#when i use gorm to gets decimal field value from mysql,whatever this struct dield type is float32,float64 or shopspring/decimal,it gets all 0

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

Which database and its version are you using?

mysql 5.6.23

Models:

package main

import (
	"log"
	"github.com/shopspring/decimal"
)

func main() {
	month := "201805"
	t := "2018-05-07"
	companyUser, _ := CompanyUserRepo.GetDaily(month, t)
	for _, cu := range companyUser {
		log.Println(cu.Ks3Storage)
	}
}

type CompanyUser struct {
	Ks3Storage float64  // or float32 or decimal.Decimal
}

var CompanyUserRepo = new(CompanyUser)

func (*CompanyUser) GetDaily(month string,
	date string) ([]*CompanyUser, error) {

	var cs []*CompanyUser
	table := "company_user_201805"
	err := db.LogMode(true).Table(table).Where("stat_date=?",
		date).Find(&cs).Error
	if err != nil {
		return nil, err
	}
	return cs, nil
}

then output is always 0,whatever the real value is.

What am I doing wrong here ? Or how I should do ?

@youtwo123
Copy link
Author

@jinzhu ,please!

@limoli
Copy link

limoli commented Oct 31, 2018

@jinzhu Confirm that it would be nice and useful having this support!

@github-actions
Copy link

github-actions bot commented Jul 9, 2020

This issue will be automatically closed because it is marked as GORM V1 issue, we have released the public testing GORM V2 release and its documents https://v2.gorm.io/docs/ already, the testing release has been used in some production services for a while, and going to release the final version in following weeks, we are still actively collecting feedback before it, please open a new issue for any suggestion or problem, thank you

Also check out https://github.com/go-gorm/gorm/wiki/GORM-V2-Release-Note-Draft for how to use the public testing version and its changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant