Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3618906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:48:43+00:00 2026-05-18T22:48:43+00:00

We have WPF based application using Prism Framework. We have embedded IronPython and using

  • 0

We have WPF based application using Prism Framework. We have embedded IronPython and using Python Unit Test framework to automate our application GUI testing.

It works very well. We have difficulties in comparing two float numbers.

Example C#

class MyClass
{
   public object Value { get; set;}
   public MyClass()
   {
        Value = (float) 12.345;
   } 
}

In IronPython When I compare the MyClass Instance’s Value property with python float value(12.345), it says it doesn’t equal

This Python statement raises assert error

self.assertEqual(myClassInstance.Value, 12.345)

This Python statement works fine.

self.assertEqual(float(myClassInstance.Value.ToString()), 12.345) 

When I check the type of the type(myClassInstance.Value), it returns Single in Python where as type(12.345) returns float. How to handle the C# float to Python comparison without explicit conversions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:48:44+00:00Added an answer on May 18, 2026 at 10:48 pm

    I’m not familiar with Python but I’m taking a stab at an answer based on what I know about the CLR and C#.

    In your example, the float value is “boxed” when it’s assigned to the Value property. Boxing is a way of storing a value type (such as a float, int, etc) in an object-typed variable. If the assert method takes two object parameters, it might be doing reference equality in which case the two would not be “equal”. You would need to “unbox” the Value property to get a value comparison. In C# this is done by simply casting the object-typed variable back to its original type.

    To demonstrate, see the following code. Note that it prints False for the first and True for the second.

    void Main()
    {
        object value1 = 1234.5F;
        object value2 = 1234.5F;
        Console.WriteLine(AreEqual(value1, value2));
        Console.WriteLine(AreEqual((float)value1, (float)value2));
    }
    
    bool AreEqual(object value1, object value2) {
        return value1 == value2;
    }
    
    bool AreEqual(float value1, float value2) {
        return value1 == value2;
    }
    

    However, I have to agree with Ignacio that you should never compare two floating point numbers for equality. You should always use a method that includes a tolerance since floating point operations can sometimes result in tiny differences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application based on PRISM that utilizes the MVVM pattern. I
I have developed a GUI for a random application using WPF. I have a
I have a WPF project based upon Prism Feb 2009 release set up as:
I have a small WPF application based on MVVM priniciples. So far I had
We have a WPF application, based on Unity with MMVVVM pattern. In application life
I'm teaching an introductory class to programming and GUI development using Python, and have
I'm developing a WPF application using MVVM. Inside a Window, I have a control
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a WPF application in VS 2008 with some web service references. For
I have a WPF window for editing database information, which is represented using an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.