C#小数字符串货币 [英] c# Decimal to string for currency

查看:138
本文介绍了C#小数字符串货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要显示我们做一个货币:

To display a currency we do:

ToString("0.##")

有关值 5.00 输出为:

5

有关值 5.98 输出为:

5.98

有关值 5.90 输出为:

5.9

我需要第三种情况为拿出2小数点,如:

I need the third case to come out with 2 decimal points, eg:

5.90

我怎么能做到这一点没有它影响其他的结果吗?

How can I do this without it affecting the other results?

推荐答案

我知道这不会给你解决问题的格式,但它是一个简单的解决方案来解决它。

I know this doesn't give you a format that fixes the problem, but it's a simple solution to work around it.

(5.00).ToString("0.00").Replace(".00","");  // returns 5
(5.90).ToString("0.00").Replace(".00", ""); // returns 5.90
(5.99).ToString("0.00").Replace(".00", ""); // returns 5.99

这篇关于C#小数字符串货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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