Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cant get a decimal result (VB6)

Posted on 2009-07-09
8
Medium Priority
?
441 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 93

Accepted Solution

by:
Patrick Matthews earned 672 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 664 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 664 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

722 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