Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable which has a value suppose '25.00' in one of its column , how can I convert it to '25'.
I have tried somethings out but it didn't worked out. might be silly mistake please help
Note: I cannot change the datatype present. I have the datatable fetched with me.
Posted
Comments
Sandeep Mewara 16-May-12 9:06am    
1. How have you used table to show data. Grid? Table bind? How exactly?
2. Whatever you tried you say, you failed because of some error?

1 solution

If you cannot change the data type to decimal (which would be the preferred solution), you can fetch the string data from a row and then use Decimal.TryParse Method[^].

Now you would have an actual number in your hand and then format it as you like for example using Decimal.ToString Method (String)[^].

Noet: Watch out the decimal separator. If the data is from different culture, you may have to replace the decimal separator used in the data with current cultures decimal separator
 
Share this answer
 
Comments
VJ Reddy 16-May-12 19:47pm    
Good answer and suggestion. 5!
Wendelius 17-May-12 4:22am    
Thanks :)

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