user1790563 - 1 year ago 90

C# Question

**Example: These Two values will come simultaneously ..**

- if comes as
`Value`

I have to to multiply it by`0.56`

and pass it as`100`

`56`

- if comes as
`Value`

then I have to divide it by`56.0`

`100`

I tried this with the following code

`string s = "56.0" or "0.56"`

float dval;

bool bval = float.tryparse(s,out dval);

if (bval)

{

dval = decimal.parse(s); // if dal ="0.56"

dval = dval*100;

}

else

{

dval = decimal.parse(s); // if dal ="56"

dval = dval/100;

}

How can I do this because every time this returns

`True`

Answer Source

`TryParse`

returns `true`

if it sucessfully parsed a number. So, it's `true`

in both cases.
You need to check whether the parsed number is less 1 or bigger (this is my speculation, of course) Try this:

```
string s = "56.0";
float dval;
bool bval = float.TryParse(s, out dval);
if (bval)
{
if (dval < 1)
dval *= 100;
else
dval /= 100;
Console.WriteLine(dval);
}
else
{
Console.WriteLine("it's not a number");
}
```