Reputation: 9131
I am writing a logging system for our site and it looks at changes to Entities to see if they should be logged. I keep having a problem where the version of the Entity in the database shows decimal numbers (in string format) as "132.0000" and the current Entity has it as "132" with no decimal places. Is there a way that I can force it to either remove the ".0000" from one or add it to the other?
Upvotes: 0
Views: 3255
Reputation: 46591
You can try:
if(132 == Convert.ToDecimal("132.0000")
{
//Do Stuff
}
Replace 132 and "132.0000" with your appropriate values.
Also, if you wanted to remove the decimal portion of "132.0000", you can do:
string dec = "132.0000";
dec = dec.Substring(0,dec.IndexOf("."));
Upvotes: 1
Reputation: 17010
Provided all of the comparisons are numerics, you have to find the commonality between the two. In your post, you have already provided the answer. You need an integral number rather than a floating point number. Cast both strings to one of the integral types and compare.
Upvotes: 0
Reputation: 174329
Hm, simply parse the value from the database into a decimal and compare it to the decimal you already have?
Upvotes: 2
Reputation: 751
If you always want to remove the decimal, why not cast the object to an int and then make a string of it?
Upvotes: 0