SQL小数问题

发布于 2024-08-11 17:21:47 字数 378 浏览 4 评论 0 原文

我有一个以下格式的输入字符串: 12.34

当我调用此行时:

db.AddInParameter(insertMessageDetailCommand, "AttachmentSize", System.Data.SqlDbType.Decimal  , Convert.ToDecimal(this.messageEnvelope.EnvelopeInfo.AttachmentSize));

我得到一个格式不正确的输入字符串。我正在部署的服务器具有带有“,”小数分隔符的区域设置。但其他生产服务器可能有“.”。分隔符。

我怎样才能将这个字符串值:12.34传递给这个函数,这样它就不会中断,并且它的通用性足以承受您向它抛出的任何区域设置?

I have an input string in the following format: 12.34

When I call this line:

db.AddInParameter(insertMessageDetailCommand, "AttachmentSize", System.Data.SqlDbType.Decimal  , Convert.ToDecimal(this.messageEnvelope.EnvelopeInfo.AttachmentSize));

I get an input string not in the correct format. The server I am deploying to have regional settings with a "," separator for decimals. But other production servers could have "." separators.

How can I pass this string value : 12.34 to this function so that it doesn't break, and its generic enough to withstand any regional setting you throw at it?

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

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

发布评论

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

评论(1

烂人 2024-08-18 17:21:48

解析字符串时指定区域性以消除服务器设置中的差异。您可以使用 InvariantCulture,它使用句点作为小数点分隔符:

Convert.ToDecimal(this.messageEnvelope.EnvelopeInfo.AttachmentSize, CultureInfo.InvariantCulture)

Specify a culture when you parse the string to elliminate differences in server settings. You can use InvariantCulture, which uses period as decimal separator:

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