我如何在Google点击转换上存储美元和美分的转换价值?

发布于 2025-02-12 08:29:45 字数 1062 浏览 0 评论 0原文

在Google的文档,他们不太很好地描述conversionValue参数。他们说这一定是一个数字价值。但是,通常在编程中具有数值的时间,传递数字会变成浮点,而且有时会丢失精度,与输入相比,您会出乎意料的输出。例如,在某些电子商务API中,他们希望您通过将价值乘以100来克服这个浮点问题。因此,假设我想在该领域通过“ 0.01”。如果我以0.01而不是在字符串中,API是否足够灵活?或者,如果我将其包裹为“ 0.01”之类的字符串,它会在没有浮点精度问题的情况下自动计算其数值吗?或者,我是否需要像对待许多电子商务API一样对待它并将其乘以100并将其传递为(0.01*100)或1?

我正在使用REST API将点击转换发布到Google广告。 我需要知道如何指定conversionValue的数值,并且需要知道,如果我将其作为“ 0.01”作为JSON中的双引用字符串,如果它可以工作或者如果它将其计算为零,因为它不是数值的值?

还要注意 so so atrate 并没有真正回答,因为它作为 tracking的值谈论的值Pixel 将转换转换为Google的版本,而不是用于发布离线转换的JSON API值。有趣的是,这是如此的海报似乎有某种证明Google将此价值存储为双倍,尽管我看不到任何文件。我也不知道API在传递到此值时如何处理“ 0.01”的字符串,以及它是否以双重格式将其转换为0.01,以使其不会在该数据上失去精确度。

In Google's Click Conversion object documentation, they do not describe the conversionValue parameter very well. They say it must be a numerical value. However, often times with numerical values in programming, there are some issues with numbers being passed that become floats and the precision can sometimes be lost, giving you an unexpected output compared to your input. For instance, in some eCommerce APIs, they want you to overcome this float problem by passing monetary values by multiplying the value by 100. So, let's say I want to pass '0.01' in this field. Is the API flexible enough if I pass it as 0.01 and not in a string? Or if I wrap it as a string like '0.01', will it automatically compute its numerical value with no float precision issue? Or, do I need to treat it like many eCommerce APIs and multiply it by 100 and pass it as (0.01*100) or 1?

I'm using the REST API for posting click conversions to Google Ads. I need to know how to specify the numerical value for conversionValue, and need to know that if I pass it as "0.01" as a double-quoted string in the JSON, if it will work or if it will compute it as zero because it wasn't a numerical value?

Note also that this SO article doesn't really answer because it's talking about the value as a tracking pixel version of posting the conversion to Google, and not a JSON API value used for posting offline conversions. It was interesting to note that this SO poster seemed to have some kind of proof that Google stores this value as a Double, although I don't see any documentation for this. I also don't know how the API treats a string of "0.01" when being passed to this value, and whether it converts it to 0.01 in a Double format in such a way that it won't lose precision on that data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2025-02-19 08:29:45

Google ADS API团队的Peter Laurence通过电子邮件于7/6/2022与我联系,并指出数值是双重的。一个人可以将值作为字符串或json传递给REST API的数字传递,它将以双重而不是float存储。

唯一的缺点是,当将10.20之类的东西作为双重存储时可能会成为10.2,但您至少不会损失美分,也不会发生舍入。

Peter Laurence from the Google Ads API Team got back to me via email on 7/6/2022 and indicated that the numerical value is a double. One can pass the value as a string or a number with the JSON passed to the REST API and it will store as a double, not a float.

The only drawback is that something like 10.20 might end up as a 10.2 when stored as a double, but you won't lose at least the cents and no rounding occurs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文