如何显示特定文化的原生数字而不是阿拉伯数字? [英] How can I display culture-specific native digits instead of Arabic numerals?

查看:220
本文介绍了如何显示特定文化的原生数字而不是阿拉伯数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个数值转换为字符串,显示特定文化的数字。例如,在阿富汗使用的达里语(文化名PRS-AF)使用东部,阿拉伯数字代替阿拉伯数字的大多数西方文化中使用的( 0,1,2,3,4,5, 6,7,8,9 )。

I want to convert a numeric value to a string, displaying culture-specific digits. For example, the Dari language used in Afghanistan (culture name "prs-AF") uses Eastern-Arabic numerals instead of the Arabic numerals used in most Western cultures (0,1,2,3,4,5,6,7,8,9).

在检查建成框架CultureInfo类,它列出了正确的本地数字拍摄(截图从LinqPad输出):

When examining the CultureInfo class built into the Framework, it lists the correct native digits (screenshot taken from output in LinqPad):

CultureInfo.CreateSpecificCulture("prs-AF").NumberFormat.NativeDigits

然而,当试图将数字转换为字符串在文化展示,我没有得到本机位数:

However, when trying to convert a number to a string to display in that culture, I am not getting the native digits:

var number = 123.5;
var culture = CultureInfo.CreateSpecificCulture("prs-AF");
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
var text = number.ToString(culture);
Console.WriteLine(text);



谁能告诉我如何显示本机的数字?

Can anyone tell me how to display the native digits?

推荐答案

数字替代的东西,发生当显示的文本的包含的数字。

Digit substitution is something that takes place when you display text that contain digits.

这是不应该改变一个数字的字符串表示,如您所见。

It is not supposed to change the string representation of a number, as you've seen.

123.5 格式化为字符串 123.5 不管数字替换。然而,这是,的显示的使用,如果 Thread.CurrentThread.CurrentCulture 相应的字形进行相应设置,如果呈现引擎支持数字替代。 (WPF不支持)

The number 123.5 is formatted as the string 123.5 no matter digit substitution. It is, however, displayed with the appropriate glyphs if Thread.CurrentThread.CurrentCulture is set accordingly and if the presentation engine supports digit substitution. (WPF do support it)

这篇关于如何显示特定文化的原生数字而不是阿拉伯数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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