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. no rounds

no rounds

Scheduled Pinned Locked Moved C#
question
5 Posts 4 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.
  • K Offline
    K Offline
    Kenny Chen
    wrote on last edited by
    #1

    i hv problems below: a = 123456.789 b = 7 c = a/b --> the result is 17636.6841 but i want it shows 17636 (not rounding to 17637) can anyone helps??? thx, cool-a

    L realJSOPR J K 4 Replies Last reply
    0
    • K Kenny Chen

      i hv problems below: a = 123456.789 b = 7 c = a/b --> the result is 17636.6841 but i want it shows 17636 (not rounding to 17637) can anyone helps??? thx, cool-a

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Math.Floor(17636.6841);

      1 Reply Last reply
      0
      • K Kenny Chen

        i hv problems below: a = 123456.789 b = 7 c = a/b --> the result is 17636.6841 but i want it shows 17636 (not rounding to 17637) can anyone helps??? thx, cool-a

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        There are a lot of solutions to your problem, but you didn't tell us whether or not you're displaying the number, or merely want to omit the fractional part from further calculations. Assuming you just want to display, it, do it this way:

        string cString = Convert.ToInt32(c).ToString();

        If you want to change the actual value, you can use Math.Floor, or even Convert.ToInt32 (I think).

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        1 Reply Last reply
        0
        • K Kenny Chen

          i hv problems below: a = 123456.789 b = 7 c = a/b --> the result is 17636.6841 but i want it shows 17636 (not rounding to 17637) can anyone helps??? thx, cool-a

          J Offline
          J Offline
          Jordon4Kraftd
          wrote on last edited by
          #4

          Review the "Math" library. There is a "Floor" and "Ceiling" function. Ceiling rounds 1.1 to 2 and Floor makes 1.9 to 1. You will need to make sure a and b are "double" but will be fine.

          double a = 123456.789;
          double b = 7;
          double c = Math.Floor(a/b);

          1 Reply Last reply
          0
          • K Kenny Chen

            i hv problems below: a = 123456.789 b = 7 c = a/b --> the result is 17636.6841 but i want it shows 17636 (not rounding to 17637) can anyone helps??? thx, cool-a

            K Offline
            K Offline
            Kenny Chen
            wrote on last edited by
            #5

            thx all... it helps me lot

            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