|
-
Sep 9th, 2008, 04:34 PM
#1
Thread Starter
Junior Member
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")
-
Sep 9th, 2008, 04:36 PM
#2
Fanatic Member
Re: Format number
Use FormatNumber("123.45678", 3)
-
Sep 9th, 2008, 04:59 PM
#3
Thread Starter
Junior Member
Re: Format number
Still returning 1 decimal place.
FormatNumber(CDbl(Value), 3, , , vbTrue)
Last edited by belebala; Sep 9th, 2008 at 05:06 PM.
-
Sep 9th, 2008, 05:31 PM
#4
Fanatic Member
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?
-
Sep 10th, 2008, 09:19 AM
#5
Thread Starter
Junior Member
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
-
Sep 10th, 2008, 09:27 AM
#6
Re: Format number
Then display it that way - but you cannot store it that way in a Double, only in a String.
-
Sep 10th, 2008, 09:40 AM
#7
Thread Starter
Junior Member
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.
-
Sep 10th, 2008, 10:07 AM
#8
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).
-
Sep 10th, 2008, 02:01 PM
#9
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
-
Sep 10th, 2008, 08:48 PM
#10
Junior Member
Re: Format number
vb Code:
Private Sub Command1_Click()
Dim parse() As String
Dim X As String
If InStr(Text1.Text, ".") Then
parse = Split(Text1.Text, ".")
X = Left(parse(1), 3)
Text1.Text = parse(0) & "." & X
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|