我想将十进制值转换为最接近的十进制数 [英] I want to covert the decimal values to the nearest decimal number

查看:93
本文介绍了我想将十进制值转换为最接近的十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
晚上好
我想将十进制值转换为最接近的十进制数,即
假设我的值是

87.6408
那么O/P如果小于5则应为60,大于5则应为70
87.60或87.70
任何帮助将不胜感激.我试过了
noo = Math.Round(noo,2,MidpointRounding.ToEven);还有
noo = Math.Round(noo,2,MidpointRounding.AwayFromZero);这正在工作,但不是我想要的.请帮忙.谢谢您

Hello friends,
Good Evening
I want to covert the decimal values to the nearest decimal number i.e
Suppose my value is

87.6408
then O/P should be either 60 if below 5 and 70 above 5
87.60 or 87.70
Any help will be appreciated. I have tried
noo = Math.Round(noo, 2,MidpointRounding.ToEven);and also
noo = Math.Round(noo, 2,MidpointRounding.AwayFromZero);This is working but not as I want. Please help.Thank You

推荐答案

double noo = Convert.ToDouble(txttotalamount.Text);
noo = Math.Round(noo, 1);
                  
string numString = string.Format("{0:###0.00}", Math.Round(noo, 2, MidpointRounding.AwayFromZero));


try:

try:

roundnoo = Math.Round(noo, 2); 





or


转换十进制ToString(#.##")
这导致"12345.67"
从字符串中读取最后一个字符,并确定它应该向下还是向上(60或70)
Convert the decimal ToString("#.##")
this leads to "12345.67"
Read the last char from string and decide if it should be down or up (60 or 70)


这篇关于我想将十进制值转换为最接近的十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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