The silly answer would be: find the location of the .
in your string, and then check the location+4.
The more serious would be, have a look at the double formatting options :)
You could use this formatting of double
// using the F4: 1054.3224
and then if the last index of your string is 0, cut it out using substring.
As of your last edit (if((val * 10000) % 10 != 0) ...
), yes, it should work ... Sudhakar suggested the same in his answer.
You should probably take whichever solution you go with, and put it in a helper method that returns an int, and then you can just use that in your code, helping your readability, and reusalibilyt :)
Go with Marks solution, simplest I guess.
double d = 3.40;
Console.Out.WriteLine("d 0.0: {0}", d); // 3.4
Console.Out.WriteLine("d 0.0: {0}", d.ToString("0.0")); // 3.4
Console.Out.WriteLine("d 0.00: {0}", d.ToString("0.00")); // 3.40
Console.Out.WriteLine("d 0.0#: {0}", d.ToString("0.0#")); // 3.4
Do notice that if all you have is 3 or 4 digts after the .
, the default would be truncated and removed as you can see if the first output above.