Results 1 to 5 of 5

Thread: getting answer to two decimal places

  1. #1
    Guest
    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!

  2. #2
    Guest

    answer

    change the return value from double to string

  3. #3
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    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

  4. #4
    Guest

    o yeah

    Thanks for all your help its much appreciated

  5. #5
    New Member
    Join Date
    Sep 2000
    Location
    Nova Scotia, Canada
    Posts
    10

    Smile

    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
  •  



Click Here to Expand Forum to Full Width