开发者

Double.ToString("C") Returning Incorrect Currency Symbol

I have the following code,

        txtCaseworkCost.Text = _CaseworkCost.ToString("C")

For some reason, the output in the text boxes looks like this,

Double.ToString("C") Returning Incorrect Currency Symbol

With some strange symbol instead of a dollar sign. The local for the computer is the United States so it should be displaying the $ sign.

The control is being used in an AutoCAD plugin, where AutoCAD loads the .Net dll. The strange part, If I use this same control in a windows form application, it works fine wit开发者_StackOverflowh the correct symbols. The incorrect symbol only appears when the code is loaded from the other application.

Is there any workaround for this? I have no control over how AutoCAD loads the dll, so I need to somehow correct the currency symbol from my code. Also, this error also appears in the reporting tool we use, so I am looking for a solution other than manually inserting the symbol.


You need to override whatever the current culture is.

Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
txtCaseworkCost.Text = _CaseworkCost.ToString("C", culture)


You cannot control the Thread.CurrentCulture in a plug-in scenario. The thread is initialized and configured by AutoCAD which may well have changed its default language for its own purposes. SetThreadLocale() in the winapi.

So if you want dollars then make sure to use the overrides that accept an IFormatProvider argument and pass the Culture.NumberFormatInfo you want.


Set the current culture in your add-in as whatever you like the symbol to appear good in then things are done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜