如何在C#编码中显示精确的数据库值. [英] How to display to exact database value in C# coding.

查看:76
本文介绍了如何在C#编码中显示精确的数据库值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,
我在C#网页上显示一些问题.
在c#网页中,来自数据库的值不是整数,它显示为0.977777777777,但我只想0.98.我也尝试在存储过程中使用圆图函数,但是它不起作用.
实际上在我的表中它显示为0.98,但在网页中它显示为0.977777777777.Grid视图直接从数据库中获取值,并显示0.977777777的实例值为0.98.我真的不明白什么是确切的问题以及如何解决.
任何人都告诉我确切的问题是什么.

问候,
Ravi

Dear Sir,
I have some displaying problem in C# web page.
In c# web page the value that coming from database is not round figure and it show 0.977777777777 but i want only 0.98 . I also try round figure function in stored procedure, but its not work.
Actually in my table value it show 0.98 but in web page its show 0.977777777777.The Grid view directly fetch the value from data base and show the value 0.977777777 instence of 0.98. I am really not understand what exact problem and hows its solved.
Any body tell me whats exact problem.

Regards,
Ravi

推荐答案

在存储过程中尝试一下.应该可以.
Try this in stored procedure. It should work.
SELECT ROUND(columnname, 2, 1) from tablename    // 2 is decimal place


尝试一下
decima d = ......
label1.text = string.Format("{0:f2}",d);
try this
decima d=......
label1.text=string.Format("{0:f2}",d);


在C#中尝试

Try in C#

String.Format("{0:0.00}", 123.4567);      // "123.46";



参考: http://www.csharp-examples.net/string-format-double/ [ ^ ]



Ref: http://www.csharp-examples.net/string-format-double/[^]


这篇关于如何在C#编码中显示精确的数据库值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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