Solved

Cant get a decimal result (VB6)

Posted on 2009-07-09
8
380 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
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MSSQL 2014 Query Synthax 8 38
Managing SQL log files, SQL Server 2014 6 55
Sql query for filter 12 21
sql calculate averages 18 25
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now