Can I limit the size of a double?

Posted on 2006-04-04
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?



Arrays are defined as

dim d () as double
Question by:bradbritton
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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?
    LVL 96

    Accepted Solution

    Are you talking about Math.Round(number, 4) to round to 4 decimal digits?

    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    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")

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now