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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. rounding to five decimal digits

rounding to five decimal digits

Scheduled Pinned Locked Moved .NET (Core and Framework)
tutorialquestion
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
    CICCIOLO69
    wrote on last edited by
    #1

    I'll try to explain : look this example : Module Module1 Sub Main() Dim num AsDouble = 1.25 Console.WriteLine(Math.Round(num, 1, MidpointRounding.AwayFromZero)) num = 1.225 Console.WriteLine(Math.Round(num, 2, MidpointRounding.AwayFromZero)) num = 1.2225 Console.WriteLine(Math.Round(num, 3, MidpointRounding.AwayFromZero)) num = 1.22225 Console.WriteLine(Math.Round(num, 4, MidpointRounding.AwayFromZero)) num = 1.222225 Console.WriteLine(Math.Round(num, 5, MidpointRounding.AwayFromZero)) num = 1.2222225 Console.WriteLine(Math.Round(num, 6, MidpointRounding.AwayFromZero)) EndSub End Module The output of this sample console application is : 1,3 1,23 1,223 1,2223 1,22222 1,222223 Is there something wrong ? In my application I must use five decimal digits and this round method. Regards Andrea

    L S G 3 Replies Last reply
    0
    • C CICCIOLO69

      I'll try to explain : look this example : Module Module1 Sub Main() Dim num AsDouble = 1.25 Console.WriteLine(Math.Round(num, 1, MidpointRounding.AwayFromZero)) num = 1.225 Console.WriteLine(Math.Round(num, 2, MidpointRounding.AwayFromZero)) num = 1.2225 Console.WriteLine(Math.Round(num, 3, MidpointRounding.AwayFromZero)) num = 1.22225 Console.WriteLine(Math.Round(num, 4, MidpointRounding.AwayFromZero)) num = 1.222225 Console.WriteLine(Math.Round(num, 5, MidpointRounding.AwayFromZero)) num = 1.2222225 Console.WriteLine(Math.Round(num, 6, MidpointRounding.AwayFromZero)) EndSub End Module The output of this sample console application is : 1,3 1,23 1,223 1,2223 1,22222 1,222223 Is there something wrong ? In my application I must use five decimal digits and this round method. Regards Andrea

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

      VB.NET forum

      Luc Pattyn [Forum Guidelines] [My Articles]


      Voting for dummies? No thanks. X|


      1 Reply Last reply
      0
      • C CICCIOLO69

        I'll try to explain : look this example : Module Module1 Sub Main() Dim num AsDouble = 1.25 Console.WriteLine(Math.Round(num, 1, MidpointRounding.AwayFromZero)) num = 1.225 Console.WriteLine(Math.Round(num, 2, MidpointRounding.AwayFromZero)) num = 1.2225 Console.WriteLine(Math.Round(num, 3, MidpointRounding.AwayFromZero)) num = 1.22225 Console.WriteLine(Math.Round(num, 4, MidpointRounding.AwayFromZero)) num = 1.222225 Console.WriteLine(Math.Round(num, 5, MidpointRounding.AwayFromZero)) num = 1.2222225 Console.WriteLine(Math.Round(num, 6, MidpointRounding.AwayFromZero)) EndSub End Module The output of this sample console application is : 1,3 1,23 1,223 1,2223 1,22222 1,222223 Is there something wrong ? In my application I must use five decimal digits and this round method. Regards Andrea

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #3

        The original message is here[^].

        Scott Dorman

        Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


        Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

        1 Reply Last reply
        0
        • C CICCIOLO69

          I'll try to explain : look this example : Module Module1 Sub Main() Dim num AsDouble = 1.25 Console.WriteLine(Math.Round(num, 1, MidpointRounding.AwayFromZero)) num = 1.225 Console.WriteLine(Math.Round(num, 2, MidpointRounding.AwayFromZero)) num = 1.2225 Console.WriteLine(Math.Round(num, 3, MidpointRounding.AwayFromZero)) num = 1.22225 Console.WriteLine(Math.Round(num, 4, MidpointRounding.AwayFromZero)) num = 1.222225 Console.WriteLine(Math.Round(num, 5, MidpointRounding.AwayFromZero)) num = 1.2222225 Console.WriteLine(Math.Round(num, 6, MidpointRounding.AwayFromZero)) EndSub End Module The output of this sample console application is : 1,3 1,23 1,223 1,2223 1,22222 1,222223 Is there something wrong ? In my application I must use five decimal digits and this round method. Regards Andrea

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

          CICCIOLO69 wrote:

          num = 1.222225 Console.WriteLine(Math.Round(num, 5, MidpointRounding.AwayFromZero))

          Um, use your brain just a little bit. num = 1.222225 Console.WriteLine(num) What answer did you get when you tried this?

          Gary

          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