+ Reply to Thread
Results 1 to 8 of 8

Formatting numerical output using Debug.Print [in code]

  1. #1
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Formatting numerical output using Debug.Print [in code]

    I want to display 3 decimal places when outputting the value of a double even if it has trailing zeroes. For instance, if I have s = 3.400 and I use Debug.Print(s), I only get 3.4 displayed. How can I format the output?
    Last edited by 6StringJazzer; 11-01-2018 at 02:29 PM. Reason: Updated title to workaround forum bug when last word of subject is "print"

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formatting numerical output using Debug.Print [in code]

    Please Login or Register  to view this content.
    where d is your variable or expression
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Formatting numerical output using Debug.Print [in code]

    Thank you, Jeff!

  4. #4
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Formatting numerical output using Debug.Print [in code]

    When using that code within VBA, I get a compile error on Format. Does it need something else included?

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formatting numerical output using Debug.Print [in code]

    No. What is your compile error? Can you show the code?

    Here is the exact code I used to confirm it.

    Please Login or Register  to view this content.
    output:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Formatting numerical output using Debug.Print [in code]

    Really odd. I copied your line, but I'm using my variable which is a double and it changes the word Format to format and then doesn't compile. Here is my code...

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Formatting numerical output using Debug.Print [in code]

    Nevermind. I see the problem. I have two variables with the same name.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formatting numerical output using Debug.Print [in code]

    Yes, Format is a built-in function. It is not a good idea to name variables after any predefined values or built-in functions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Debug.Print Error
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2014, 11:10 PM
  2. What does Debug.Print do?
    By KRAND in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2013, 04:39 AM
  3. Excluding formatting from print output
    By JohnnyCash in forum Excel General
    Replies: 7
    Last Post: 02-18-2010, 08:04 AM
  4. How to format TextBox output as numerical
    By knarf in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-15-2009, 02:52 PM
  5. Debug.Print Problem
    By jhl84 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-24-2007, 04:07 AM
  6. how to debug and get an output
    By sa02000 in forum Excel General
    Replies: 1
    Last Post: 12-14-2006, 12:35 AM
  7. Replies: 1
    Last Post: 08-24-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1