在c#.net中显示浮点值 [英] display float value in c#.net

查看:63
本文介绍了在c#.net中显示浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何将浮点值从数据库中检索到asp.net

解决方案

hai nabinaya,

您只需编写查询从表中选择值"并将结果存储为十进制值

使用下面的代码显示值

 十进制 amt =(Convert.ToDecimal(dt.Rows [ 0 ] [" ].ToString())).ToString(  0.00"); 



不要忘记标记它是否是您的解决方案. :-)


使用第二种解决方案将更有可能解决您的问题.我记不清了,但是我不确定ToString()方法是否可以使用.

您需要提供某种格式的十进制值.

代替:

.ToString(" ); 



请执行以下操作:

.ToString("  123 . 45 ); // "123.45" 
.ToString("  4 ); // "123.4" 
.ToString("  0 ); // "123"  


Hi,

how to retrive float values from database into asp.net

解决方案

hai nabinaya,

you can simply write query "select value from table" and store the result in decimal value


Hi, use below code to show the value

decimal amt = (Convert.ToDecimal(dt.Rows[0]["Amount"].ToString())).ToString("0.00");



Don''t forget to mark if it is your solution. :-)


Using the 2nd solution that will more than likely resolve your issue. I can''t remember exactly but I''m not sure the ToString() method will work.

You need to provide some kind of formatting for the decimal value.

Instead of:

.ToString("0.00");



Do this:

.ToString("{0: 0.##}", 123.45);      // "123.45"
.ToString("{0: 0.##}", 123.4);       // "123.4"
.ToString("{0: 0.##}", 123.0);       // "123"


这篇关于在c#.net中显示浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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