0

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?

6 Answers 6

2

Hm, simply parse the value from the database into a decimal and compare it to the decimal you already have?

Sign up to request clarification or add additional context in comments.

Comments

1

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("."));

Comments

1

Convert the entry back to decimal, I'd say.

Comments

0

If you always want to remove the decimal, why not cast the object to an int and then make a string of it?

1 Comment

what you mean is "fraction", decimal is a C# datatype
0

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.

Comments

-1

You can use formatter string : F4 xxx.ToString("F4")

1 Comment

No, generally, the School of Converting Everything to String for Comparison is wrong, e.g. with floating point, you'll loose information in string conversion, if done non-carefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.