Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 货币格式_C#_.net - Fatal编程技术网

C# 货币格式

C# 货币格式,c#,.net,C#,.net,请帮助我为货币格式构建自己的函数: 我在这里为addPadding创建了一个函数,现在我需要一个formatCurrency方法 例如: class Program { static void Main(string[] args) { Console.WriteLine(addPadding("2567675432", 18, "R", "*")); Console.ReadKey(); } public static Stri

请帮助我为货币格式构建自己的函数:

我在这里为addPadding创建了一个函数,现在我需要一个formatCurrency方法

例如:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(addPadding("2567675432", 18, "R", "*"));
        Console.ReadKey();
    }

    public static String addPadding(String strInputString, int iScale, String strDirection, String strPaddingCharacter)
    {
        String strReturnValue = strInputString;
        if (strInputString.Length < iScale)
        {
            for(int i = 0; i< iScale - strInputString.Length; i++)
            {
                if (strDirection == "R") strReturnValue += strPaddingCharacter;
                if (strDirection == "L") strReturnValue = strPaddingCharacter + strReturnValue;
                if (strReturnValue.Length == iScale) break;
            }
        }
        return strReturnValue;
    }
}

此问题有多种答案,解释了如何以不同方式格式化货币:

请将问题中的代码更改为代码。为什么不能使用内置功能?请决定您使用的是-C、javascript还是java,因为您用eclipse标记了您的问题,这并不清楚。将您的电子邮件放在帖子中不是一个好主意,因为这样肯定会收到大量垃圾邮件。最好的做法是告诉我们您的方法出了什么问题。