封装float64在protobuf中的包

huangapple go评论67阅读模式
英文:

package to encapsulate float64 in protobuf

问题

我正在使用Stripe创建订阅的微服务中工作。其中一个字段在.proto文件中被设置为float,但它被转换为float32而不是float64

我无法找到直接的方法让protobuf生成一个字段类型为float64的文件。有人可以帮我吗?是否有专门用于protobuf的包可以封装float64类型?

非常感谢!

英文:

I was working in a microservice to create subscriptions in Stripe. One of the fields is listed as a float64 where I set it up as a float in the .proto file. This cast the field as a float32 not float64.

I cannot see a direct way to make protobuf to produce a file with the field typed as float64. Can someone help me here? Is there any special package for protobuf that encapsulates a float64?

Many Thanks

答案1

得分: 11

如在标量值类型中提到的那样,Go中的float64在protobuf中使用double进行定义。因此,你需要将代码从:

float a_field = 1;

修改为:

double a_field = 1;
英文:

As mentioned in Scalar Value Types, float64 in Go is defined with double in protobuf. So instead of writing:

float a_field = 1;

you will write:

double a_field = 1;

huangapple
  • 本文由 发表于 2022年5月6日 18:17:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/72139870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定