-
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!
-
answer
change the return value from double to string
-
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]
-
o yeah
Thanks for all your help its much appreciated
-
You could also use:
Format(x,"fixed")