Solved

Cant get a decimal result (VB6)

Posted on 2009-07-09
8
429 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What type of testing am I doing? 4 75
SQL Server how to use a VARIABLE to link tables in a SQL Script? 3 41
mssql 7 32
SQL query 45 38
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
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…

737 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