Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetFormat module

Posted on 2013-06-11
7
Medium Priority
?
268 Views
Last Modified: 2013-06-12
Experts,

I have this function that rounds large numbers.  It  works fine except the billions are not rounded properly.

ie:  2,699,458,000.00
rounds to 2.699458B

Public Function GetFormat(varField) As String
'USED WITH AN UNBOUND FIELD ON THE RPT AND APPENDS MM OR B
    Select Case Len(varField)
    Case 7 To 9
        GetFormat = FormatNumber(varField / 1000000, 0) & "MM"
    Case 10
        GetFormat = varField / 1000000000 & "B"
End Select
End Function

how can I make
2,699,458,000.00
round to 2.7B?

thank you
0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:pdvsa
ID: 39239193
I use the function like this:
AmtOverlay: GetFormat([contractamt])
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 39239251
Please explain what "rounded properly" would be :)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39239257
use this function


Public Function GetFormat(varField) As String
'USED WITH AN UNBOUND FIELD ON THE RPT AND APPENDS MM OR B
varField = CDec(Replace(varField, ",", ""))
    Select Case Len(varField)
    Case 7 To 9
        GetFormat = FormatNumber(varField / 1000000, 0) & "MM"
    Case 10 To 12
        GetFormat = FormatNumber(varField / 1000000000, 1) & "B"
End Select
End Function
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:pdvsa
ID: 39239294
Capricorn,

thanks.  do i need to handle nulls?  I get a runtime error 94 "Invalid use of Null".  The debugger highlights the varField line.  

thank you.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1600 total points
ID: 39239732
Public Function GetFormat(varField) As String
'USED WITH AN UNBOUND FIELD ON THE RPT AND APPENDS MM OR B

if varField & ""="" then GetFormat="": Exit Function

varField = CDec(Replace(varField, ",", ""))
    Select Case Len(varField)
    Case 7 To 9
        GetFormat = FormatNumber(varField / 1000000, 0) & "MM"
    Case 10 To 12
        GetFormat = FormatNumber(varField / 1000000000, 1) & "B"
End Select
End Function
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39240501
Just replace FormatNumber with Format and brush up a little:
Public Function GetFormat(ByVal varField As Variant) As String

' USED WITH AN UNBOUND FIELD ON THE RPT AND APPENDS MM OR B

    If IsNumeric(varField) Then
        Select Case Len(varField)
            Case 7 To 9
                GetFormat = Format(varField / 10 ^ 6, 0) & "MM"
            Case 10 To 12
                GetFormat = Format(varField / 10 ^ 9, 0) & "B"
        End Select
    End If

End Function

Open in new window

/gustav
0
 

Author Comment

by:pdvsa
ID: 39242042
Capricorn, very nice.  it rounded 2,699,458,000.00  to 2.7B, which is exactly what I needed.  

Gustav:  that worked too (but it did round the 2.7B to 3B).  

thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question