Solved

comparing values

Posted on 2014-01-17
2
278 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
[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
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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