Can I limit the size of a double?

I have an array of doubles, which range is size from 0.6803939303238393921 to 27.4995966002839211038 . I need to limit the numbers to a length of 4, but I cannot limit thier size until I place them in a specific array as they are used in calculations. Any ideas?



Arrays are defined as

dim d () as double
Who is Participating?
Bob LearnedCommented:
Are you talking about Math.Round(number, 4) to round to 4 decimal digits?

Mike TomlinsonMiddle School Assistant TeacherCommented:
Do you really want to truncate your digits and lose accuracy?

Why not just display them with four digits using ToString() when you need to present them to the user?
Mike TomlinsonMiddle School Assistant TeacherCommented:
For example...

        Dim d As Double = 0.68039393032383944
        Dim strD As String = d.ToString("#0.0000")

        Dim d2 As Double = 27.499596600283922
        Dim strD2 As String = d2.ToString("#0.0000")
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.