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 Places

Decimal Places

Scheduled Pinned Locked Moved C#
questioncsharplearning
3 Posts 3 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.
  • R Offline
    R Offline
    Reinier van de Wetering
    wrote on last edited by
    #1

    How can i specify how many decimal places is displayed when i parse a double to a string?? Sorry, i'm still a beginner with c#!

    R 1 Reply Last reply
    0
    • R Reinier van de Wetering

      How can i specify how many decimal places is displayed when i parse a double to a string?? Sorry, i'm still a beginner with c#!

      R Offline
      R Offline
      Rampas Tomas
      wrote on last edited by
      #2

      Fairly simple: double d = 2.12165464578784545; string s = d.ToString("#.##"); Tomas Rampas ------------------------------ Systems analyst, MCSD rampas(at)gedas(dot)cz http://www.gedas.com/ ------------------------------

      H 1 Reply Last reply
      0
      • R Rampas Tomas

        Fairly simple: double d = 2.12165464578784545; string s = d.ToString("#.##"); Tomas Rampas ------------------------------ Systems analyst, MCSD rampas(at)gedas(dot)cz http://www.gedas.com/ ------------------------------

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        If you want to maintain a precision of 2, use "#.00" instead of "#.##" so that 0 will be used when no number exits in that position.

        Microsoft MVP, Visual C# My Articles

        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