We help IT Professionals succeed at work.

Can I limit the size of a double?

bradbritton
bradbritton asked
on
Medium Priority
193 Views
Last Modified: 2010-04-23
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
Comment
Watch Question

Mike TomlinsonHigh 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.

Ask the Experts
Mike TomlinsonHigh 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)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

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

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.