本地化-从丹麦语(da-dk)到英语的货币会话. [英] Localization - Currency conversation from danish(da-dk) to english.

查看:100
本文介绍了本地化-从丹麦语(da-dk)到英语的货币会话.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中本地化货币值时遇到问题

我的想法是,我想显示丹麦(da-DK)文化的货币值,并且相同的值将以英语格式存储在DB中.我正在使用NumberFormatInfo更改为所选区域性的货币.

示例:

如果选择丹麦语(da-DK),则货币值为100.000,56

我要在数据库中存储的值是100000.56


代码如下.

TextBox1.Text = 100.000,56;

double dblDBvalue;

dblDBvalue = Convert.ToDouble(TextBox1.Text.ToString()=="?"0":TextBox1.Text.ToString(),NumberFormatInfo.InvariantInfo);

当我想从丹麦语转换为英语时,此代码给出了抛出错误.

I have problem in localizing currency value in asp.net

The idea is that I want to display the currency value for the Danish (da-DK) culture and the same value will be store in DB as english format . I am using NumberFormatInfo to change to currency for the selected culture.

Example:

if I select Danish (da-DK) ,the currency value is 100.000,56

I want to store the value in Database is that 100000.56


The code is below.

TextBox1.Text = 100.000,56;

double dblDBvalue ;

dblDBvalue=Convert.ToDouble(TextBox1.Text.ToString() == "" ? "0" : TextBox1.Text.ToString(),NumberFormatInfo.InvariantInfo );

This code is giving throw error, when I want to convert from Danish to englsh.

thanks in advance.

推荐答案

一个简单的提示应该可以解决所有问题:在dabatased和数据管理中,更普遍的是,除了UI之外,几乎所有其他地方,都不要这样做. t使用数据的字符串表示形式,使用数据本身.使用适当的数据库数据类型,例如数字.您不仅可以节省空间和数据处理,还可以避免麻烦.避免解析字符串和无效数据;仅当来自用户输入时才分析或解释数据,这是区域性敏感的,容易出错,但易于阅读,

文化只是它的另一个好处.数据是文化中立的,它的字符串表示不是.在所有文化中,二进制格式的100.000,56都是相同的.如果这是浮点,则受标准IEEE 754(请参见)等等.

—SA
Just one simple hint which should resolve everything: in dabatased and data management, and, more generally, almost anywhere except the UI, don''t work with string representation of data, work with data itself. Use appropriate database data types, such as numeric. Not only you save on space and processing of data, you save yourself from trouble. Avoid parsing strings and invalid data; you parse or interpret data only when if comes from the user input, which is culture sensitive, error prone but human-readable,

Cultures is just one additional benefit of it. Data is culture-neutral, its string representation is not. Your 100.000,56 in binary form is the same in all cultures. If this is floating-point, it is governed by standard IEEE 754 (see), and so on.

—SA


只有一个简单的提示可以解决所有问题:在数据和数据管理中,更普遍的是,除了UI之外,几乎没有其他地方使用数据的字符串表示形式,使用数据本身.使用适当的数据库数据类型,例如数字.您不仅可以节省空间和数据处理,还可以避免麻烦.避免解析字符串和无效数据;仅当来自用户输入时才分析或解释数据,这是区域性敏感的,容易出错,但易于阅读,

文化只是它的另一个好处.数据是文化中立的,它的字符串表示不是.在所有文化中,二进制格式的100.000,56都是相同的.如果这是浮点,则受标准IEEE 754(请参见)等等.



回应对此答案的评论:

请在我建议依赖指定为您的线程文化的文化中查看我的评论;有两个单独的属性:System.Threading.Thread.CurrentCultureSystem.Threading.ThreadCurrentUICulture:
http://msdn.microsoft.com/en-us/library/system. threading.thread.currentculture.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. threading.thread.currentuiculture.aspx [ ^ ].

您可以在运行时中的任何时间分配区域性.附属程序集将根据我在以下注释中描述的 fallback 机制加载.当然,它不会立即更改应用程序的外观,因为仅当您使用资源时,资源中的数据才会出现,因此您将需要使涉及到并与文化相关的任何内容无效.

在您的显式计算中,线程的CurrentCulture会影响不是文化中立的方法的行为.此外,API还允许您将区域性作为参数传递.让我们考虑例如double.ToString:
http://msdn.microsoft.com/en-us/library/shxtf045.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/d8ztz0sa.aspx [ ^ ].

尝试使用它们传递System.Globalization.CultureInfo实例,其中接口类型为System.IFormatProvider的参数应为预期值.您可以这样做,因为此类实现了此接口.如果这样做,则将根据指定区域性的要求对字符串进行格式化.请参阅:
http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system.globalization. cultureinfo.aspx [ ^ ].

—SA
Just one simple hint which should resolve everything: in dabatases and data management, and, more generally, almost anywhere except the UI, don''t work with string representation of data, work with data itself. Use appropriate database data types, such as numeric. Not only you save on space and processing of data, you save yourself from trouble. Avoid parsing strings and invalid data; you parse or interpret data only when if comes from the user input, which is culture sensitive, error prone but human-readable,

Cultures is just one additional benefit of it. Data is culture-neutral, its string representation is not. Your 100.000,56 in binary form is the same in all cultures. If this is floating-point, it is governed by standard IEEE 754 (see), and so on.



In response to comments to this answer:

Please see my comment where I advice to rely on the culture specified as the culture of your thread; there are two separate properties: System.Threading.Thread.CurrentCulture and System.Threading.ThreadCurrentUICulture:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx[^].

You can assign the culture at any time during run-time. The satellite assemblies will be loaded according the fallback mechanism I described in comments below. Of course, it won''t change the look of the application immediately, as the data from resources will come up only when you use them, so you will need to invalidate anything which is involved and culture-dependent.

In your explicit calculations, the CurrentCulture of the thread affects the behavior of the methods which are not culture-neutral. Besides, the API allows you to pass culture as a parameter. Let''s consider, for example, double.ToString:
http://msdn.microsoft.com/en-us/library/shxtf045.aspx[^],
http://msdn.microsoft.com/en-us/library/d8ztz0sa.aspx[^].

Try to use them passing the instance of the System.Globalization.CultureInfo where the parameter of the interface type System.IFormatProvider is expected. You can do it because this class implements this interface. If you do that, the string will be formatted as required by the specified culture. Please see:
http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx[^].

—SA


这篇关于本地化-从丹麦语(da-dk)到英语的货币会话.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆