将0转换为0.0,将1转换为1.0,依此类推 [英] Convert 0 to 0.0 , 1 to 1.0 and so on

查看:150
本文介绍了将0转换为0.0,将1转换为1.0,依此类推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的值为0,1,2 ......等等.我将其转换为double后将其四舍五入为小数点后一位.对于十进制后有数字的值,它工作正常,但如果bot正常工作,则可以正常工作数字是100或数字,十进制后没有数字.我想要100的结果是100.0,依此类推.

请帮助

Hi All,


I have values as 0,1,2 ......so on.I have converted it into double after that I round off it to 1 decimal place.It is working fine for values having digit after decimal but bot working fine if the digit is 100 or numbers without having digits after decimal. I want result as 100.0 for 100 and so on.

Please Help

推荐答案

由于decimal point without any number following it does not have any significance as a value后的0在double value中不可用.

但是,在将double number表示为string 时,可以使用适当的Format 指示符将其显示为如下所示:
Since, the 0 after the decimal point without any number following it does not have any significance as a value it is not available in the double value.

However, while representing the double number as a string it can be shown using an appropriate Format specifier as follows:
double value = 100;
string valueAsString = value.ToString("N1");
Console.WriteLine (valueAsString);
//Output
//100.0


要显示逗号等,其他Formats 在此处 http://msdn. microsoft.com/en-us/library/dwhawy9k(v=vs.71).aspx [


To show commas etc. other Formats given here http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.71).aspx[^] can be used.


lblshowresult.Text = String.Format(" { 0:INR#,## 0.00},Convert.ToDecimal(SumTotal));
lblshowresult.Text = String.Format("{0:INR #,##0.00}", Convert.ToDecimal(SumTotal));


这篇关于将0转换为0.0,将1转换为1.0,依此类推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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