如何显示特定于文化的本地数字而不是阿拉伯数字?

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)

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)