Solved

Cant get a decimal result (VB6)

Posted on 2009-07-09
8
437 Views
Last Modified: 2012-05-07
Hi Experts
I need to get a result to 2 decimal places but my calculations always seem to round of to integers.

Dim SumPurchaseRates as long
Dim NrOfClients as long

Debug.print "Average purchase rate = " & Format ((SumPurchaseRates / NrOfClients), "###0.00")  
Debug.print = 9.00  (when using  7022/758)

ie I'd like an answer of 9.26. (in VB6) Please help......

0
Comment
Question by:peterdarazs
[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
8 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 168 total points
ID: 24812029
Hello peterdarazs,

You have to declare at least one of the variables as Single or Double.  When both dividend and divisor are
Long or Integer, then the result will also be Long or Integer.

Regards,

Patrick
0
 
LVL 31

Assisted Solution

by:RiteshShah
RiteshShah earned 166 total points
ID: 24812060
well, I agree with Matthew... if you divide INT by INT, it will return int so "SumPurchaseRates" should be single or double. Moreover, you have raised question in MS SQL Server zone so I guess you are fetching data right from there, in that case, you should do this operation in SQL Query itself.
0
 
LVL 7

Assisted Solution

by:Chandan_Gowda
Chandan_Gowda earned 166 total points
ID: 24812066
This should work....Please check
Dim SumPurchaseRates as double
Dim NrOfClients as double

Debug.print "Average purchase rate = " & Format ((SumPurchaseRates / NrOfClients), "###0.00")  
Debug.print = 9.00  (when using  7022/758)

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24812100
hi Chandan,

that will work for sure but actually don't need to define both variable as double, first one will do the job. even, it is depends on author, how he should go for.........
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 24812111
yes ritesh.... you are right...
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24812123
actually my concern was to save few bits of memory by declaring only one variable as double.
0
 

Author Closing Comment

by:peterdarazs
ID: 31601502
Hi Thanks guys - I hope you don;t mind  if share the points for those 3 quick answers (unfortunately someone has dimmed the point window as INt so we can't quite do 166.66 ) Close enough anyway. Mega thanks ......
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24812134
welcome, glad to help!!!

Ritesh Shah
www.SQLHub.com
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

615 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