format a double to 8 decimal places

♀尐吖头ヾ 提交于 2020-01-06 03:35:13

问题


I have a method that i want to return as a double with 8 dp.

so i have a value coming back from a sp and in the code i am simply doing

CheckSum = double.Parse(cmd.ExecuteScalar().ToString());

however, if the sp returns this :1541338.2349537 the returned double only has those 7dp, when i would like it to put a trailing zero on. like this.. 1541338.23495370

i cant find a method on the double to format it - ie force it to 8dp, other than to return a formatted string. which i dont want to do. can someone explain please :)

thanks

nat


回答1:


double d = 0.123456789;
string sDisplayValue = d.ToString("0.00000000");



回答2:


double inputValue = 14.42564678942; inputValue = Math.Round(inputValue, 8);

output is 14.42564679

This will preserve the double and will not need a conversion to string



来源:https://stackoverflow.com/questions/4884749/format-a-double-to-8-decimal-places

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!