Results 1 to 10 of 10

Thread: Format number

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    28

    Format number

    I'm trying to format a number to 3 decimal places (eg. 123.45678 to 123.457, but it is returning 123.5). Anyone has an idea?

    Format$(CDbl(Value), "####.000")

  2. #2
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759

    Re: Format number

    Use FormatNumber("123.45678", 3)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    28

    Re: Format number

    Still returning 1 decimal place.

    FormatNumber(CDbl(Value), 3, , , vbTrue)
    Last edited by belebala; Sep 9th, 2008 at 05:06 PM.

  4. #4
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759

    Re: Format number

    I'm not sure what you are doing wrong, but this works.

    MsgBox FormatNumber(CDbl(312.123456), 3)

    It returns 312.123

    What is the number you are formatting?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    28

    Re: Format number

    My number is 14.3 as a String, then I use CDbl to convert it to double. I want this number to display as 14.30

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Format number

    Then display it that way - but you cannot store it that way in a Double, only in a String.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    28

    Re: Format number

    I have a list of numbers, showing in 1, 2 and 3 decimal places. I want display them all in 3 decimal places. I've tried just use FormatNumber(Value), 3, , , vbTrue) and FormatNumber(CStr(Value), 3, , , vbTrue), both of them returned the original decimal places.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Format number

    Show us the actual code you are using (not just part of a line, but the relevant section of code and variable declarations).

  9. #9
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Format number

    Note that all 1001 of these numbers display in a list box exactly three places to the right of the decimal:

    Code:
    For I = 0 To 1000
        List1.AddItem Format$(Sqr(9 + I), "###.000")
    Next
    Doctor Ed

  10. #10
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Format number

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim parse() As String
    3. Dim X As String
    4. If InStr(Text1.Text, ".") Then
    5. parse = Split(Text1.Text, ".")
    6. X = Left(parse(1), 3)
    7. Text1.Text = parse(0) & "." & X
    8. End If
    9. End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width