Solved

comparing values

Posted on 2014-01-17
279 Views
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.
0
Question by:metropia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 13

Accepted Solution

akb earned 500 total points
ID: 39789623
The problem is that you are comparing strings, not numbers.

I don't program in Visual Basic.net but I think you need to use Convert.toDecimal().

i.e.
If  Convert.toDecimal(myHistoryRecipeRecord.MeltPointHigh =  Convert.toDecimal(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
0

Author Comment

ID: 39789684
You got it!
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses
Course of the Month6 days, 8 hours left to enroll