开发者

java DecimalFomat in C#

I have these code which I have converted from Java. Now I need to change this DecimalFormat in C# Syntex.

private string formatValue(double dVal)
        {
            DecimalFormat df = new DecimalFormat();开发者_StackOverflow社区
            df.applyPattern("######.###");
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
            dfs.DecimalSeparator = '.';
            df.DecimalFormatSymbols = dfs;
            return df.format(dVal);
        }

Kindly help me to do the same.

Thanks!


Use number.ToString("######.###") to achieve the same in C#


I hope this will help:

var nf = new System.Globalization.NumberFormatInfo();
nf.NumberDecimalSeparator = "-";
double d = 123456.789;
d.ToString("########.###",nf);//prints 123456-789
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜