|
-
Oct 5th, 2000, 09:19 AM
#1
I have a function,
Public Function toTwoDecimals(x As Double) As Double
toTwoDecimals = (Format(x, "0.00"))
End Function
it reduces decimals to only two decimal places. Thats ok but if you get an answer like 123.30 it prints it out as 123.3. I was just wondering if anbody knew some code to put in the function so i will get the 0 as well?
I thought that if I added in the code below it would work, but it didn't:
IIf((x * 100) Mod 10 = 0, x & "0", x)
Thanks!
-
Oct 5th, 2000, 09:39 AM
#2
answer
change the return value from double to string
-
Oct 5th, 2000, 09:43 AM
#3
Addicted Member
Hi,
Use FormatNumber instead of Format:
ie:
Code:
Dim MyNumber As Double
dim strNumber As String
MyNumber = 1.2034
strNumber = FormatNumber(MyNumber,2) 'Set to 2 Decimal Place
'strNumber now equals 1.20
Hope this helps
Shaun
[Edited by S@NSIS on 10-05-2000 at 10:45 AM]
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Oct 5th, 2000, 10:41 AM
#4
o yeah
Thanks for all your help its much appreciated
-
Oct 5th, 2000, 11:45 AM
#5
New Member
You could also use:
Format(x,"fixed")
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
|