将数字格式化为钱

Format number as money(将数字格式化为钱)
本文介绍了将数字格式化为钱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数字格式化为如下所示:9,000我的数据库字段是金钱数据类型,当我把它拉出来时,我看到它是这样的:9000.0000在我看来不正确(我希望它看起来像一种真钱格式)

How do I format a number to look like this: 9,000 my database field is in money data type, when I pull it up I see it like this: 9000.0000 that don't look right to me (I would like it to look like a real money format)

推荐答案

虽然你可以调用 string.format,但我认为调用 ToString 就可以了.

While you could call string.format, I think it's easier to just call ToString on it.

decimal money = 9000m;
string formattedMoney = money.ToString("C");

这篇关于将数字格式化为钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)