Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 31-May-11 21:40pm
v4

Try this in stored procedure. It should work.
SELECT ROUND(columnname, 2, 1) from tablename    // 2 is decimal place
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 1-Jun-11 2:21am    
Close but no cigar! Rounding to two decimal places will yield 0.99 instead of 0.98 as OP requested.
Toniyo Jackson 1-Jun-11 2:30am    
See the updated answer
That's Aragon 1-Jun-11 2:45am    
Good call Toniyo. Have my 5
Ravi Sharma 2 1-Jun-11 3:36am    
Actually sir,
In table irs show 0.98 but in C# Web page , its show 0.977777777.
I am not understand , whats exact problem.
That's Aragon 1-Jun-11 5:10am    
Can you post the C# code here where you get the value from DB or set to any variable ?
try this
decima d=......
label1.text=string.Format("{0:f2}",d);
 
Share this answer
 
Comments
Ravi Sharma 2 1-Jun-11 3:38am    
Actually sir,
In table its show 0.98 but in C# Web page, its show 0.977777777.my data type is number.The web page gridview directlly fetch value from database.
I am not understand , whats exact problem.
Try in C#

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


Ref: http://www.csharp-examples.net/string-format-double/[^]
 
Share this answer
 
Comments
arindamrudra 1-Jun-11 2:31am    
He want 123.45 in stead of 123.46.
Parwej Ahamad 1-Jun-11 3:00am    
As posted question description, I posted the solution. Otherwise he can use Math.Round function.
arindamrudra 1-Jun-11 3:36am    
The question is been edited. So now it is correct.
Ravi Sharma 2 1-Jun-11 3:38am    
Actually sir,
In table its show 0.98 but in C# Web page, its show 0.977777777.my data type is number.
I am not understand , whats exact problem.
Parwej Ahamad 1-Jun-11 3:41am    
Can you post here your conversion code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900