使用c#进行十进制舍入 [英] decimal round off using c#

查看:105
本文介绍了使用c#进行十进制舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有12.5的价值我希望输出像这样的格式12.0和16.6这个值我需要输出17.0 plz帮助我先生

I am having value for 12.5 i want output like this format 12.0 and 16.6 this value i need output 17.0 plz help me sir

推荐答案

试试这个:

Try this:
double before1 = 12.5;
double after1 = Math.Round(before1);
Console.WriteLine(after1.ToString("F1", CultureInfo.CurrentCulture));

decimal before2 = 12.5M;
decimal after2 = Math.Round(before2);
Console.WriteLine(after2.ToString("F1", CultureInfo.CurrentCulture));



了解更多:标准数字格式字符串 [ ^ ]


试试这个

Try this
double outputValue = 0;

outputValue = Math.Round(your_decimal_value, 0);
Console.WriteLine(string.Format("{0:#0.0}", outputValue));


简单的Math.Round方法将满足您的目的。
Simply Math.Round method will serve your purpose.


这篇关于使用c#进行十进制舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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