asp.net mvc的一套数字格式默认小数千位分隔符 [英] asp.net mvc set number format default decimal thousands separators
本文介绍了asp.net mvc的一套数字格式默认小数千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何能同时设置默认的小数点和千位分隔符,无论格式化文化在asp.net mvc的号码是多少?
How can I set both default decimal and thousands separator for formatting number in asp.net mvc regardless of culture?
推荐答案
我将张贴code终于为我工作。在控制器上OnActionExecuting功能:
I will post the code that finally worked for me. On controller, on OnActionExecuting function:
ViewBag.CurrentNumberFormat = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
ViewBag.CurrentNumberFormat.NumberDecimalDigits = 2;
ViewBag.CurrentNumberFormat.NumberDecimalSeparator = "~";
ViewBag.CurrentNumberFormat.NumberGroupSeparator = " ";
和中查看:
@((1234567.435).ToString("#,###.##", ViewBag.CurrentNumberFormat))
这篇关于asp.net mvc的一套数字格式默认小数千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文