本文介绍了C#CultureInfo NumberFormat NumberDecimalSeparator问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将应用程序的NumberDecimalSeparator更改为。至 /。当我在文本框中显示浮点数时,它起作用。但是完全不显示整数类型。

I want to change NumberDecimalSeparator of my application from "." to "/". it works when i show float numbers in my textbox. but integer types are not shown at all.

我修改线程的区域性以获取应用程序范围的格式。我的代码是这样的:

I modify thread's culture to get application-wide formatting. my code is like this:

CultureInfo ci = new CultureInfo("fa-IR", true);
ci.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
ci.NumberFormat.NumberDecimalSeparator = "/";
Thread.CurrentThread.CurrentCulture = ci;

结果:

3.14 => 3/14
100 =>

3.14 => "3/14"100 => ""

有任何帮助吗?

推荐答案

我只是创建了这样的测试控制台应用程序,但是得到了这样的输出:

I just create such testing console application but have got a output like this:

Input next value:
3.14
3/14
Input next value:
100
100

我的代码是:

using System;
using System.Globalization;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            CultureInfo ci = new CultureInfo("en-US", true);            
            Thread.CurrentThread.CurrentCulture = ci;
            Console.WriteLine("Input next value:");
            string input = Console.ReadLine();

            while (input != "e")
            {
                double dblInput = double.Parse(input);
                CultureInfo ci2 = new CultureInfo("fa-IR", true);
                ci2.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
                ci2.NumberFormat.NumberDecimalSeparator = "/";
                Thread.CurrentThread.CurrentCulture = ci2;

                Console.WriteLine(dblInput);
                Console.WriteLine("Input next value:");
                input = Console.ReadLine();
            }
        }
    }
}

是这里有一些不适用于您的问题吗?

Is here something not applicabale to your question?

这篇关于C#CultureInfo NumberFormat NumberDecimalSeparator问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:25