我有一个以下格式的输入字符串: 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?
发布评论
评论(1)
解析字符串时指定区域性以消除服务器设置中的差异。您可以使用
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: