Solved

Cant get a decimal result (VB6)

Posted on 2009-07-09
8
413 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
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

790 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