Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I have a field in database of type numeric(10,5)
in this field user enters data it can be 22 or 22.22 or 22.2222 or anything.
Now my problem is when i retrieve the data using select query and bind to datagridview it displays 22.00000 or 22.22000 or 22.22220 bu i want 22 ,22.22 and 22.2222 respectively.
can u say how can i achieve this
Posted

C#
double dblValue = 2222.22220;;
Console.WriteLine(dblValue.ToString("N", CultureInfo.InvariantCulture));
// Displays 2,222.22

Console.WriteLine(dblValue.ToString("N1", 
                  CultureInfo.CreateSpecificCulture("sv-SE")));
// Displays -12 445,7

int intValue = 123456789;
Console.WriteLine(intValue.ToString("N1", CultureInfo.InvariantCulture));
// Displays 123,456,789.0

For more info http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^]
http://stackoverflow.com/questions/1872094/how-to-display-numeric-in-3-digit-grouping[^]
http://stackoverflow.com/questions/2360372/digit-grouping-in-net[^]
http://www.dreamincode.net/forums/topic/226278-c%23-menu-digit-grouping/[^]
 
Share this answer
 
Comments
Hetal Jariwala 1-Nov-12 8:44am    
cann't it be done using sql query....???
Sushil Mate 1-Nov-12 8:45am    
show us the query?
fjdiewornncalwe 1-Nov-12 9:49am    
The sql query is there to provide data. Your issue is dealing with the display of that data. That should be dealt with from the code that consumes the data rather than the data source.
C#
double value = 22.2222;
double result;
double.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out result);

use result where you want.
 
Share this answer
 
Comments
Hetal Jariwala 1-Nov-12 8:44am    
cann't it be done using sql query....???

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