Solved

comparing values

Posted on 2014-01-17
2
277 Views
Last Modified: 2014-01-17
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
Comment
Question by:metropia
2 Comments
 
LVL 13

Accepted Solution

by:
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

by:metropia
ID: 39789684
You got it!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question