tags:

views:

130

answers:

4

Having some issue with this...

    if (System.Convert.ToInt32(TotalCost(theOrder.OrderData.ToString()).ToString()) < 10000)
        ViewData["cc"] = "OK";
    else
        ViewData["cc"] = "NO";

yields: "Input string was not in a correct format."

How can I check if the number inside the string is less than 10000?

Oh yeah: TotalCost returns a ContentResult of type text/plain

+3  A: 

First use Int32.TryParse to see if the string is a number that falls into the range of Int32.

If the result is a number, you can always compare it to whatever limit you have.

int i;
if (int.TryParse(theOrder.OrderData, out i))
{
    if (i < 10000)
    {
       // Do stuff...
    }
}
Mark Seemann
+1. Good answer, and you beat me to it.
David Stratton
+1  A: 

use Int32.TryParse()

David Stratton
A: 
int value = Convert.ToInt32(TotalCost(theOrder.OrderData.ToString()));
if (value < 10000)
{
    // ...
}
bobbymcr
A: 

description: How to check if a string is numberic or integer

Hai...

Here is the solution for the problem

link text

Thanks!

Murugan Andezuthu Dharmaratnam

muruganad
Hi and welcome to SO. A couple of pointers...its better to actually show the solution rather than linking to a page as the linked page may be taken down in the future so SO would lose the answer. Its also not necessary to sign your name.
Si Keep