Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Why the following condition is never met?

Why the following condition is never met?

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xkx32
    wrote on last edited by
    #1

    double number1 = 1, number2 = .5; while (number1 > number2) { number1 -= .1; MessageBox.Show(number1.ToString()); if (number1 == number2) MessageBox.Show("condition met"); // <- never :( } Please help

    D 1 Reply Last reply
    0
    • X xkx32

      double number1 = 1, number2 = .5; while (number1 > number2) { number1 -= .1; MessageBox.Show(number1.ToString()); if (number1 == number2) MessageBox.Show("condition met"); // <- never :( } Please help

      D Offline
      D Offline
      Dustin Metzgar
      wrote on last edited by
      #2

      Floats are not guaranteed to be perfectly accurate because of the way they're stored. What are the numbers you get in your message box as it goes down? You may want to give Decimal a try.


      Logifusion[^]

      X 1 Reply Last reply
      0
      • D Dustin Metzgar

        Floats are not guaranteed to be perfectly accurate because of the way they're stored. What are the numbers you get in your message box as it goes down? You may want to give Decimal a try.


        Logifusion[^]

        X Offline
        X Offline
        xkx32
        wrote on last edited by
        #3

        thanks, Decimal worked

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups