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

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

问题描述

我想将数值转换为字符串,显示特定于文化的数字.例如,阿富汗使用的达里语(文化名称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天全站免登陆