comparing two values

navagomeza

Member
Joined
Jan 13, 2014
Messages
12
Programming Experience
1-3
hello I am having trouble figuring out a method to compare two values that seem to be the same, but the number of decimal places is affecting the logic and I am not sure how to format the values correctly.

One of the values is an entity record field = 100.00000000000000000000
The other value is from a detailsview cell = 100.00

When I run this code:
                    If String.Equals(myHistoryRecipeRecord.MeltPointHigh, DirectCast(dvRecipeItem.Rows(6).Cells(1).Controls(0), TextBox).Text) Then
                        strRefineRecipeRecord.Append("MeltPointHigh: " & myHistoryRecipeRecord.MeltPointHigh & ", ")
                    Else
                        strRefineRecipeRecord.Append("MeltPointHigh: Old= " & myHistoryRecipeRecord.MeltPointHigh &
                                                     ", New= " & DirectCast(dvRecipeItem.Rows(6).Cells(1).Controls(0), TextBox).Text & ", ")
                    End If

It always fall to the else because the number of decimal places.

I have search for examples on how to format decimals coming from an entity record field, but I have not found anything that I can understand.

If any one could please explain to me how this can be done, that would be great.

Thank you so much.
 
Last edited by a moderator:
If you're having an issue with decimal places then you're comparing the values as Strings but the values are obviously numeric so why are you not comparing them as numbers? Numbers don't have format so issues like this never arise.

Where is that code exactly and why are you referencing controls in a grid cell? Please provide a FULL and CLEAR explanation of what you're trying to achieve and why, rather than just how.
 
Of course the strings are different. They each have a different number of characters. Convert each string to a type Double and then compare the numbers.
 
Back
Top