All,
I am doing a basic calculation as follows: - FiscalRatio = countfiscalsafety / countfiscalaccidents
-
Debug.Print countfiscalsafety / countfiscalaccidents
-
Debug.Print FiscalRatio
The output of these debug.prints is
Why is access/the vba rounding the 1.666 up to 2?
I would like to just see the 1.66 to 2 decimal places such as 1.67 is produced.
Hi. NeoPa was spot-on here as at line 8 you've defined FiscalRatio as Long - hence the whole-number conversion. Double would be more appropriate.
Don't know what Ratio at line 7 is used for, as it does not appear to be referred to in your code, but it also is defined as a Long. If it is going to be used as its name says to represent a ratio then it should be a Double too.
-Stewart
5 2367 NeoPa 32,556
Expert Mod 16PB
I would guess it's to do with the variable type of FiscalRation, but that's not included in your question so it's hard to say.
I expect, with the necessary information, we may be able to give a fuller answer.
- Private Sub Command89_Click()
-
On Error GoTo jumpout
-
Dim countsafetyconcerns As Long
-
Dim countaccidents As Long
-
Dim countfiscalsafety As Long
-
Dim countfiscalaccidents As Long
-
Dim Ratio As Long
-
Dim FiscalRatio As Long
-
-
-
Me.txtCountAccidents = CountingIncidents(cmboMonth, cmboYear, Me.cmboDept, 1)
-
Me.txtCountSafetyConcerns = CountingIncidents(cmboMonth, cmboYear, Me.cmboDept, 3)
-
-
countsafetyconcerns = Me.txtCountSafetyConcerns
-
countaccidents = Me.txtCountAccidents
-
-
-
If countaccidents = 0 Then
-
countaccidents = 1
-
Else
-
End If
-
-
Ratio = countsafetyconcerns / countaccidents
-
Me.txtRatio = Ratio
-
-
-
Me.txtFiscalAccidents = FiscalCountingIncidents(Me.cmboMonth, Me.cmboYear, Me.cmboDept, 1)
-
Me.txtFiscalSafetyConcerns = FiscalCountingIncidents(Me.cmboMonth, Me.cmboYear, Me.cmboDept, 3)
-
-
countfiscalsafety = Me.txtFiscalSafetyConcerns
-
countfiscalaccidents = Me.txtFiscalAccidents
-
-
If countfiscalaccidents = 0 Then
-
countfiscalaccidents = 1
-
Else
-
End If
-
-
FiscalRatio = countfiscalsafety / countfiscalaccidents
-
Debug.Print countfiscalsafety / countfiscalaccidents
-
Debug.Print FiscalRatio
-
Me.txtFiscalRatio = FiscalRatio
-
-
completedyo:
-
Exit Sub
-
-
jumpout:
-
MsgBox Err.Description & " - " & Err.Number
-
Resume completedyo
-
End Sub
Hi. NeoPa was spot-on here as at line 8 you've defined FiscalRatio as Long - hence the whole-number conversion. Double would be more appropriate.
Don't know what Ratio at line 7 is used for, as it does not appear to be referred to in your code, but it also is defined as a Long. If it is going to be used as its name says to represent a ratio then it should be a Double too.
-Stewart
NeoPa 32,556
Expert Mod 16PB
As Stewart so correctly says, Long is explicitly integral. It's essentially an Integer type but uses 32 bits instead of just 16.
Your code assigns the value to this Long variable, which must necessarily convert it to an integer to store it. Single & Double are floating point type variables, but depending on your requirements, you may want to look at Decimal or Currency alternatives. The help pages can highlight the benefits of each and indicate which is best for your requirements.
Dimensioning my ratios as double has fixed the issue. Thanks guys!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Allen Thompson |
last post by:
Is there a script that will round off a number to a certain number of
decimal places? -Allen Thompson
|
by: Deano |
last post by:
One thing that slightly annoys me about my app is a side-affect from the way
it processes figures. It calculates salaries very precisely (to the penny)
but there are rounding issues that cause...
|
by: Lynn N. |
last post by:
I have a report showing Rate, Hours and Total Pay (which is
Rate*Hours) for several workers. I want to sum the Total Pay and get
a CORRECT figure. This seems like it should be such a simple task....
|
by: Klaus Bonadt |
last post by:
I have found strange behaviour in casting floating point values in C++ 6.0
to int:
If I enter in the watch window while debugging in version 6.0 the following
term:
(1.4 - 1.0) * 10.0
the...
|
by: Jeff Boes |
last post by:
(asked last week on .questions, no response)
Can anyone explain why this happens? (under 7.4.1)
select '2004-05-27 09:00:00.500001-04' :: timestamp(0) ;
timestamp
---------------------...
|
by: Cygnus |
last post by:
Sorry in advance for the lack of formatting in this posting.
Data:
(column headers)
Net Sales | Royalty Rate | Total Royalty
(data)
4.31 | 50.00% | 2.15
19.35 | 50.00% | 9.68
|
by: beach.dk |
last post by:
Hi,
I'm trying to implement a simple hash algorith called rs_hash in
javascript,
but I cannot get a correct result.
In c the code looks like this:
|
by: rak53820 |
last post by:
pls give java code for this Calculation :
Premium for 1 year (For members who have joined the group before policy issuance):
Basic Premium (A) = (Basic Rate * SA/1000 or SA/100000Round...
|
by: md |
last post by:
Hi
Does any body know, how to round a double value with a specific number
of digits after the decimal points?
A function like this:
RoundMyDouble (double &value, short numberOfPrecisions)
...
|
by: bdsatish |
last post by:
The built-in function round( ) will always "round up", that is 1.5 is
rounded to 2.0 and 2.5 is rounded to 3.0.
If I want to round to the nearest even, that is
my_round(1.5) = 2 # As...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |