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. Decimals missing

Decimals missing

Scheduled Pinned Locked Moved C#
helpquestion
2 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.
  • S Offline
    S Offline
    Stefan R
    wrote on last edited by
    #1

    Hello. I want to do something like this: float number = 3 / 2; The problem is that the decimals don't show up, all that is displayed is "1" instead of 1.5. I have tried using float/double/decimal but still the decimals disappear. What's wrong? Am I missing something here?

    R 1 Reply Last reply
    0
    • S Stefan R

      Hello. I want to do something like this: float number = 3 / 2; The problem is that the decimals don't show up, all that is displayed is "1" instead of 1.5. I have tried using float/double/decimal but still the decimals disappear. What's wrong? Am I missing something here?

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      I think you are. In this expression, the numbers 3 and 2 are integers. If you integer divide 3 by 2 you get 1. This 1 is converted to a float implicitly because no data is lost, but it's not the value you are looking for. Try:

      float number = 3.0 / 2.0;

      Regards, Rob Philpott.

      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