使用 Razor 视图引擎 - 如何将十进制值格式化为逗号和两位小数? [英] Using Razor view engine - how do I format a decimal value to have commas and two decimal places?

查看:11
本文介绍了使用 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天全站免登陆