How can I display culture-specific native digits instead of Arabic numerals?(如何显示特定于文化的本地数字而不是阿拉伯数字?)
问题描述
我想将数值转换为字符串,显示特定于文化的数字.例如,阿富汗使用的达里语(文化名称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)
这篇关于如何显示特定于文化的本地数字而不是阿拉伯数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何显示特定于文化的本地数字而不是阿拉伯数字?
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01