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. Removing Decimal Palces from a division

Removing Decimal Palces from a division

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

    Hi I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?

    D S G 3 Replies Last reply
    0
    • C cybersurferdev

      Hi I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      double d = 13/7; int i = Convert.ToInt32(d);

      1 Reply Last reply
      0
      • C cybersurferdev

        Hi I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        Math.Truncate(a/b); or Math.Floor(a/b);


        www.troschuetz.de

        1 Reply Last reply
        0
        • C cybersurferdev

          Hi I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          That depends. Do you want to truncate or round the value? Are you going to process the value further, or is it only to be displayed? If you want to truncate the value (remove decimal part), cast the value to int or use Math.Truncate. If you want to round the value (to nearest integer), use Math.Round. If you want to round it only for displaying it, do the rounding when you convert it to a string, using ToString("n0"). --- b { font-weight: normal; }

          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