使用的Razor视图引擎 - 我怎么格式化十进制值有逗号和小数点后两位? [英] Using Razor view engine - how do I format a decimal value to have commas and two decimal places?

查看:889
本文介绍了使用的Razor视图引擎 - 我怎么格式化十进制值有逗号和小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题 - 我在我的视图模型的值是小数。我有超过没有控制权。我想使用的Razor视图引擎来显示它作为货币。

As the title suggests - I have a value in my viewmodel that is decimal. I have no control over that. I'd like to display it as currency using the Razor View Engine.

$@String.Format("{0:0.00}", 1005.3422)

让我中途那里:

$1005.34

但我怎么能得到逗号在那里呢?

but how can I get the commas in there?

感谢

推荐答案

您可以使用 {0:C} 呢?这仅仅是标准的字符串在.NET和c是为货币格式。有很多标准的数字字符串格式。而且,当然,自定义格式了。

Can you use {0:c} instead? This is just standard string formatting in .NET and the "c" is for currency. There are lots of standard numeric string formats. And, of course, custom formatting, too.

这篇关于使用的Razor视图引擎 - 我怎么格式化十进制值有逗号和小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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