在ASP.NET会计风格字符串格式 [英] Accounting Style string format in ASP.NET

查看:86
本文介绍了在ASP.NET会计风格字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道格式化字符串作为会计风格的最简单方法。我知道如何使用的货币格式{0:C}但也有在会计风格有些差异,例如,所有的美元符号将排队以及所有的小数点和底片都在括号pssed前$ P $而不是一个 - 减号。你可以找到我想它在Excel中,如果你有2位小数格式的单元格为会计学的方式一个很好的例子。

I would like to know the easiest way to format a string as accounting style. I know how to format as currency using {0:c} but there are some differences in accounting style, for example, all the dollar signs will line up as well as all the decimal points, and negatives are expressed in parenthesis rather than with a "-" minus sign. You can find a good example of the way i would like it in excel if you format the cells as "accounting" with 2 decimal places.

推荐答案

忽略你的对准要求,你可以使用

Ignoring your alignment requirements, you could use

number.ToString("€#,##0.00;(€#,##0.00);Zero")

含盖负数。

要调整你的号码,你有没有货币符号格式和垫带格式的数字自己与空间,使用固定宽度的字体会使这项工作变得更容易。

To align your numbers, you'd have to format without the currency symbol, and pad the formatted numbers yourself with spaces, using a fixed width font would make this job easier for you.

编辑:

这似乎是的String.Format你的朋友:

It seems String.Format is your friend:

String.Format("{0,15:#,##0.00 ;(#,##0.00);-   }", number)

其中15是输出的总宽度,你需要将这些内容添加到您的货币符号。 (同样,这在对齐只固定宽度)

where 15 is the total width of the output, and you need to append this text to your currency symbol. (Again, this aligns in fixed width only)

这篇关于在ASP.NET会计风格字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆