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. double precision problem

double precision problem

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

    how to set the precision of double type in c#? by default, 1/3=0.33333333333333, output from c#, If I want to the output is only 0.33, that means the output is only two number after the point. thanks

    I M 2 Replies Last reply
    0
    • S Seraph_summer

      how to set the precision of double type in c#? by default, 1/3=0.33333333333333, output from c#, If I want to the output is only 0.33, that means the output is only two number after the point. thanks

      I Offline
      I Offline
      il_masacratore
      wrote on last edited by
      #2

      double type makes round by defect. If you wan't round you have to use real...

      Visit my blog at http://dotnetforeveryone.blogspot.com

      1 Reply Last reply
      0
      • S Seraph_summer

        how to set the precision of double type in c#? by default, 1/3=0.33333333333333, output from c#, If I want to the output is only 0.33, that means the output is only two number after the point. thanks

        M Offline
        M Offline
        Malcolm Smart
        wrote on last edited by
        #3

        If it is just the display output you want :-

                static void Main(string[] args)
                {
                    double d = 1.0 / 3.0;
        
                    Console.WriteLine(d);//0.3333333333
                    Console.WriteLine("{0:0.00}", d);//0.33
                }
        

        "More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF

        "This time yesterday, I still had 24 hours to meet the deadline I've just missed today."

        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