本文介绍了如何用dyanamically舍入小数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我需要四舍五入值



Ex:2.365变为2.360

3.239变成3.230







谢谢



Afsal

Hi All ,,


I need to round a decimal value

Ex : 2.365 become 2.360
3.239 become 3.230



thanks

Afsal

推荐答案

double inVal = 2.365;
 double outVal = Math.Truncate(inVal * 100) / 100;
 string outStr = outVal.ToString("#.000");



2.360的十进制值是2.36

outVal - > 2.36

outStr - > 2.360



[Agent_Spock]



或你可以这样做


decimal value of 2.360 is 2.36
outVal ->2.36
outStr ->2.360

[Agent_Spock]

or you can do it like this

decimal value = Math.Round(Convert.ToDecimal("12.395"), 2);
string outStr  = value.ToString("#.000");



价值是12.4

outStr是12.400


value is 12.4
outStr is 12.400


System.Math.Round(x,0)


double d = 1.275;
Math.Round(d, 2);          // 1.27
Math.Round((decimal)d, 2); // 1.28 


这篇关于如何用dyanamically舍入小数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:18