We help IT Professionals succeed at work.

# Can I limit the size of a double?

on
Medium Priority
193 Views
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,

Arrays are defined as

dim d () as double
Comment
Watch Question

## View Solutions Only

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Are you talking about Math.Round(number, 4) to round to 4 decimal digits?

Bob

Not the solution you were looking for? Getting a personalized solution is easy.

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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)
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile