Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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?

Thanks,

Brad

Arrays are defined as

dim d () as double
0
bradbritton
Asked:
bradbritton
  • 2
2 Solutions
 
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?
0
 
Bob LearnedCommented:
Are you talking about Math.Round(number, 4) to round to 4 decimal digits?

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For example...

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

        Dim d2 As Double = 27.499596600283922
        Dim strD2 As String = d2.ToString("#0.0000")
        MsgBox(strD2)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now