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. decimal question

decimal question

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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    I want to have the number as ##9.9 only if there is a decimal point but if it's 0 then it should be ##0? at the same time I want to round to upper so it should 57.3 if it's 57.3 but it should be 58 if it's 57.6

    OriginalGriffO H L 3 Replies Last reply
    0
    • J Jassim Rahma

      I want to have the number as ##9.9 only if there is a decimal point but if it's 0 then it should be ##0? at the same time I want to round to upper so it should 57.3 if it's 57.3 but it should be 58 if it's 57.6

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      That isn't easy, mostly because your requirements conflict: How should 59.9 be printed? Your first requirement says "59.9", but your rounding says it should be 60. Decide exactly what you want to do, and try again! :laugh:

      I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in. Apathy Error: Don't bother striking any key.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • J Jassim Rahma

        I want to have the number as ##9.9 only if there is a decimal point but if it's 0 then it should be ##0? at the same time I want to round to upper so it should 57.3 if it's 57.3 but it should be 58 if it's 57.6

        H Offline
        H Offline
        Heinzzy
        wrote on last edited by
        #3

        if I correctly understand your post

        double i = 11157.0;
        Console.WriteLine(i.ToString("#.#"));

        else clarify it plz

        1 Reply Last reply
        0
        • J Jassim Rahma

          I want to have the number as ##9.9 only if there is a decimal point but if it's 0 then it should be ##0? at the same time I want to round to upper so it should 57.3 if it's 57.3 but it should be 58 if it's 57.6

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          if your formatting isn't one of the built-in ones, just write a method ("MyToString()") that formats it any way you like; and don't hesitate to use as many statements as you need to get it done. Then use your method everywhere it applies. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          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