Shaggy1
asked on
CONVERT varchar to integer contains commas display in GridView
I have a VARCHAR field that contains numbers representing SQ.FT. I would like to convert that to an INT and round up or down the number by 500. The results will be displayed in a GridView.
example of the field: 10,000 or 145,500....
Would really appreciate the help. I've been trying to CAST, MATH.ROUND, etc, just can't get anything to work.
example of the field: 10,000 or 145,500....
Would really appreciate the help. I've been trying to CAST, MATH.ROUND, etc, just can't get anything to work.
ASKER
VARCHAR datatype is in SQL not C#. Writing a query in C#
ASKER
So I'm retreiving the value in FIELD1 which is VARCHAR. When i run the query, i need to convert that to an INT so that i can ROUND it up or down..
Thanks!
Thanks!
Hi,
Try this
SELECT CAST(ROUND(CAST(FIELD1 AS DECIMAL) / 500, 0) * 500 AS INT)
FROM yourtable
/peter
Try this
SELECT CAST(ROUND(CAST(FIELD1 AS DECIMAL) / 500, 0) * 500 AS INT)
FROM yourtable
/peter
Once you have the value out of your database you could use the following, although it is quite ugly I must admit.
int converted = Convert.ToInt32(double.Parse("15,000"));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pivar,
If i already have the SELECT statement in place (SELECT DISTINCT) , can i still use the part CAST(ROUND(CAST etc..trying to add that in there and I am getting errors.
THANKS!
If i already have the SELECT statement in place (SELECT DISTINCT) , can i still use the part CAST(ROUND(CAST etc..trying to add that in there and I am getting errors.
THANKS!
Yes, you should be able to do that. What is the errordetails?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string mystring = "145,000";
mystring = mystring.Replace(",", "");