![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Isssue with converting double to int Hi, I have a double number and need to convert it to an int. Unfortunately it simply drops the digit(s) after the decimal point. For example: int requiredShares = (int)(1230.98); The value of requiredShares is 1230. This is not right. The correct number should be 1231 because that's the closest integer to 1230.98. In summary, what I want is to round up to 1 if it's greater than .5 and round down to 0 if it's less than .5. Anyone can tell me if there's any .NET utility that does what I want? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Isssue with converting double to int "Curious" <fir5tsight@xxxxxx> wrote in message news:3963e61e-47c1-49fc-bbe9-5dff0d5512f2@xxxxxx Quote: > Hi, > > I have a double number and need to convert it to an int. Unfortunately > it simply drops the digit(s) after the decimal point. For example: > > int requiredShares = (int)(1230.98); > > The value of requiredShares is 1230. This is not right. The correct > number should be 1231 because that's the closest integer to 1230.98. > > In summary, what I want is to round up to 1 if it's greater than .5 > and round down to 0 if it's less than .5. > > Anyone can tell me if there's any .NET utility that does what I want? int rounded = (int)System.Math.Round(1230.98, 0); Mark -- Mark Salsbery Microsoft MVP - Visual C++ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Isssue with converting double to int Quote: > int rounded = (int)System.Math.Round(1230.98, 0); |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Converting FROM .wma and .wav TO .mp3 using WMC 11 | Vista music pictures video | |||
| Converting MP4 to MP3 | Vista music pictures video | |||
| Converting a .Wim To a ISO | Vista General | |||
| copy to c:\users\default - user shell folder autocad 2008 isssue | Vista General | |||
| Converting to PDF | Vista General | |||