## ProblemYou need to round off double-precision numbers in a standard, accurate way. ## SolutionSample code folder: Chapter 06\Rounding Use the ## DiscussionThe Dim outputFormat As String = _ "Rounding value: {0} Results: {1}" Dim oneTry As String Dim result As New System.Text.StringBuilder Dim piRounded As Double Dim digits As Integer For digits = 0 To 5 piRounded = Math.Round(Math.PI, digits) oneTry = String.Format(outputFormat, digits, piRounded) result.AppendLine(oneTry) Next digits MsgBox(result.ToString()) Figure 6-8 shows the results of these rounding actions. ## Figure 6-8. Using the Math.Round( ) function to round numbers accuratelyA third optional parameter lets you fine-tune the way a number is rounded when the number is exactly halfway between two values at the point where the number is to be rounded. The choices are to have the number rounded to an even digit, or away from zero. The default is to round to an even digit. ## See AlsoSee "Math.Round" in Visual Studio Help for more information. |

Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))

ISBN: 0596101775

EAN: 2147483647

EAN: 2147483647

Year: 2006

Pages: 400

Pages: 400

Authors: Tim Patrick, John Craig

Similar book on Amazon

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net