Rounding when converting float to integer

Cint(3/2) = 2 (rounded up, I would have thought the answer would be 1)

Cint(5/2) = 2 (rounded down)

The Access help says Cint() rounds to the nearest even number, but why??

Do I need to "roll my own" integer conversion to get it to always round up 
or down?

I looked at Cint(3\2) and Cint(5\2) which seems to consistently round 
down... that may do.
-- 
regards,

Br@dley 


0
4/13/2006 12:51:37 AM
comp.databases.ms-access 42527 articles. 11 followers. Post Follow

15 Replies
223 Views

Similar Articles

[PageSpeed] 26
Br@dley wrote:
> Cint(3/2) = 2 (rounded up, I would have thought the answer would be 1)
> 
> Cint(5/2) = 2 (rounded down)
> 
> The Access help says Cint() rounds to the nearest even number, but why??
> 
> Do I need to "roll my own" integer conversion to get it to always round up 
> or down?
> 
> I looked at Cint(3\2) and Cint(5\2) which seems to consistently round 
> down... that may do.

Format(3/2)  -> 1.5  a string.  To get a number use Val(Format(3/2)).

Int(Format(3/2)) -> 1.  Int() removes the decimal.

Format(5/2) -> 2.5 a string.

Val(Format(5/2)) -> 2.5.  Int(Format(5/2)) - > 2.

-- 
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
0
me2968 (1473)
4/13/2006 2:06:52 AM
Public Function Ceiling(ByVal d As Double) As Long
Ceiling = -(Int(-d))
End Function

0
lylefairfield (1852)
4/13/2006 2:37:54 AM
MGFoster wrote:
> Br@dley wrote:
>> Cint(3/2) = 2 (rounded up, I would have thought the answer would be
>> 1) Cint(5/2) = 2 (rounded down)
>>
>> The Access help says Cint() rounds to the nearest even number, but
>> why?? Do I need to "roll my own" integer conversion to get it to always
>> round up or down?
>>
>> I looked at Cint(3\2) and Cint(5\2) which seems to consistently round
>> down... that may do.
>
> Format(3/2)  -> 1.5  a string.  To get a number use Val(Format(3/2)).
>
> Int(Format(3/2)) -> 1.  Int() removes the decimal.
>
> Format(5/2) -> 2.5 a string.
>
> Val(Format(5/2)) -> 2.5.  Int(Format(5/2)) - > 2.

Ta. I guess my main question was WHY the Cint() rounds to the nearest even 
number?? Just interested in the reasoning for implementing it that way.
-- 
regards,

Br@dley 


0
4/13/2006 2:51:28 AM
"Br@dley" <dontlookforme@google.com> wrote in
news:e1keco$1n3$1@news-02.connect.com.au: 

> MGFoster wrote:
>> Br@dley wrote:
>>> Cint(3/2) = 2 (rounded up, I would have thought the answer would be
>>> 1) Cint(5/2) = 2 (rounded down)
>>>
>>> The Access help says Cint() rounds to the nearest even number, but
>>> why?? Do I need to "roll my own" integer conversion to get it to
>>> always round up or down?
>>>
>>> I looked at Cint(3\2) and Cint(5\2) which seems to consistently
>>> round down... that may do.
>>
>> Format(3/2)  -> 1.5  a string.  To get a number use Val(Format(3/2)).
>>
>> Int(Format(3/2)) -> 1.  Int() removes the decimal.
>>
>> Format(5/2) -> 2.5 a string.
>>
>> Val(Format(5/2)) -> 2.5.  Int(Format(5/2)) - > 2.
> 
> Ta. I guess my main question was WHY the Cint() rounds to the nearest
> even number?? Just interested in the reasoning for implementing it
> that way. 

So that the sum of a bunch of rounded numbers will approximate the sum of 
the same numbers before rounding.

-- 
Lyle Fairfield
0
lylefairfield (1852)
4/13/2006 3:07:20 AM
Br@dley wrote in message <e1k7c1$lqv$1@news-02.connect.com.au> :
> Cint(3/2) = 2 (rounded up, I would have thought the answer would be 
> 1)
>
> Cint(5/2) = 2 (rounded down)
>
> The Access help says Cint() rounds to the nearest even number, but 
> why??
>
> Do I need to "roll my own" integer conversion to get it to always 
> round up or down?
>
> I looked at Cint(3\2) and Cint(5\2) which seems to consistently round 
> down... that may do.

Check out these (watch for linebreaks in the links)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deconconversionroundingtruncation.asp
http://support.microsoft.com/default.aspx?scid=kb;EN-US;196652

-- 
Roy-Vidar


0
4/13/2006 9:25:10 AM
Lyle Fairfield schreef:
> Ceiling = -(Int(-d))

Wow! A quote from the Excel 3.0 manual ... ;-)

--
Paul 


0
4/13/2006 9:58:17 AM
kaniest wrote:
> Lyle Fairfield schreef:
> 
>>Ceiling = -(Int(-d))
> 
> 
> Wow! A quote from the Excel 3.0 manual ... ;-)

Everyone learns what they know from somewhere.
0
rkc1870 (593)
4/13/2006 11:18:08 AM
That's interesting to know. I got it from:

From:	 	Paul van Goudoever - view profile
Date:		Fri, Sep 18 1998 12:00 am
Email: 		"Paul van Goudoever" <pgoud...@sig.nl>
Groups: 		comp.databases.ms-access

This one handles reals as well:

Function RoundUp5(varNum As Variant) As Long
On Error Resume Next
    If IsNumeric(varNum) Then
        RoundUp5 = -Int(-varNum / 5) * 5
    End If
End Function

Unfortuantely, Paul doesn't post here anymore.

0
lylefairfield (1852)
4/13/2006 11:29:58 AM
Lyle Fairfield
> Unfortuantely, Paul doesn't post here anymore.

Not as often as I used to but ...

Bye,
Paul 


0
4/13/2006 11:43:21 AM
Did Excel 3.0 have VB(A) enabled?

0
lylefairfield (1852)
4/13/2006 12:05:36 PM
Lyle Fairfield:
> Did Excel 3.0 have VB(A) enabled?

IIRC it had some macro language ...
A co-worker gave me the wow-comment when he saw the posting. 


0
4/13/2006 12:13:50 PM
Sorry, I wasn't clear. I meant the smart Paul. Well, you could be Paul
VG, I suppose, as I've seen smart things posted by you perviously. If
you were Paul VG you would probably have noted over the years that I
have credited you with this function on several occasions, and forgiven
me for failing to do so in a quickie reponse late at night.

0
lylefairfield (1852)
4/13/2006 12:43:01 PM
I feel a pretty dumb right now, but I still think I hardly
deserve any credits for -(int(-x)). Maybe a tiny little
bit for first posting it in cdma. 


0
4/13/2006 1:22:22 PM
I don't deserve as much credit as that. But it might help Bradley.

Assuming you are Paul VG you haven't posted much that's dumb here,
nothing that I have ever noted. If you have, it's compensated for by a
whole bunch of smart things you have posted.

So let's just forget this exchange and move forward.

0
lylefairfield (1852)
4/13/2006 1:45:21 PM
"Br@dley" <dontlookforme@google.com> wrote

 > Ta. I guess my main question was WHY the
 > Cint() rounds to the nearest even number?
 > Just interested in the reasoning for imple-
 > menting it that way.

It's called "Banker's Rounding" and it is what Microsoft chose to use, after 
conferring with their customers.

  Larry Linson
  Microsoft Access MVP


0
bouncer (4168)
4/13/2006 11:18:04 PM
Reply:
Similar Artilces:

US-TX-Round Rock: RN Stepdown.Telemetry 7a-, Graduation from a NLN accredited sc (45355957612)
US-TX-Round Rock: RN Stepdown.Telemetry 7a-, Graduation from a NLN accredited sc (45355957612) ============================================================================================== Position: RN Stepdown.Telemetry 7a- Reference: CAM00023 Location: Round Rock TX Duration: PERM Skills: Graduation from a NLN accredited school of nursing. 3-5 years experience supervision in ptient care. Experience conducting initial and ongoing assessment of the patient and family, development of a family centered patient care pla...

US-TX-Round Rock Director of Women's Servi, 3-5 years of Healthcare Management (45354832410)
US-TX-Round Rock Director of Women's Servi, 3-5 years of Healthcare Management (45354832410) ============================================================================================= Position: Director of Women's Services Reference: CAM00005 Location: Round Rock, TX Duration: Perm Skills: 3-5 years of Healthcare Management is required. Must have a Bachelor degree in area of expertise or equilivant experience. Current Texas Registered Nurse License. Certification in basic cardiopulmonary resusciation required for working in clinal/patient care area. ...

FAQ Topic
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N? ----------------------------------------------------------------------- ` Math.random() ` returns a value ` R ` such that ` 0 <= R < 1.0 `; therefore: // positive integer expected function getRandomNumber(j) { return Math.floor(j * Math.random()); } - gives an evenly distributed random integer in the range from ` 0 ` to ` j - 1 ` inclusive; use ` getRandomNumber(n)+1 ` for ` 1 ` to ` n `. http://msdn2.microsoft.com/en-us/library/41336409.aspx http://doc...

rounding FP to u significant digits
While REPRESENT provides for the creation of a string representation of a floating point number to a specified number of significant digits, there are some situations in which it is necessary to round an fp number to a fixed number of significant digits. These situations are probably rare, but I ran into one recently for the numerical solutions of eigenvectors. An word for rounding fp numbers to a specified number of significant digits is given below. Perhaps this can be shortened? KM -- \ Round fp value to u significant digits variable power \ Return power of ten factor which scales f su...

Credit card number rounding?
I am trying to print a contract for a customer specifying use of their credit card number. For some odd reason the number is being rounded. I checked - it's a text field. On the other hand, I format it as: CCNO: Format([CCNum],"0000-0000-0000-0000") The last two digits get rounded e.g. 36 becoms 40 etc. I believe it's being coerced into a numeric field before it's being formatted, and the numeric field can't support the number of significant digits you require. You may have to use String functions: CCNO: Left([CCNum], 4] & "-" & Mid([CCNum], ...

How to draw rectangles with rounded corner ?
Hello, I want to draw rectangles with rounded corners. I know the command 'setlinejoin' but I can't give it the radius. Do you know something which could help me ? thanks :) -- yves piel yvespiel <yvespielusenet@free.fr> wrote: >Hello, >I want to draw rectangles with rounded corners. I know the command >'setlinejoin' but I can't give it the radius. >Do you know something which could help me ? There is no command to do it directly. You will need to combine drawing straight lines and drawing arcs. ---------------------------------------- Aandi Inst...

rounding
Hi, I am attempting to round a number (float) to 2 decimal digits in java. How is this possible? Thanks, -- Adrien Martel cs2 One approach would be to multiply the number by 100, cast it to an int, then divide it by 100.0. This would truncate instead of round. > I am attempting to round a number (float) to 2 decimal digits in java. How > is this possible? http://www.xdweb.net/~dibblego/java/faq/answers.html#q28 -- Tony Morris http://xdweb.net/~dibblego/ <klynn47@comcast.net> schreef in bericht news:1103571572.279608.114830@c13g2000cwb.googlegroups.com... > One ap...

Rounding (COBOL and otherwise)
As a follow-up to the other "threads" on ROUNDING, I have posted a page that is an (edited) version of a paper discussed by J4 in 1993 on "rounding" and some other possible (and existing in other languages and software) approaches. Thank you to Jordan Wouk for providing his original paper to me. The edited online version may be viewed at: http://home.comcast.net/~wmklein/DOX/RNDG.htm It should be noted that even as the 2002 Standard was revised and delayed, it was felt that there was insufficient "user-demand" to extend (much less modify) the existing (tr...

Dangerous Convertion?
Hi, I want to convert CString to LPBYTE like LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring; is it very dangerous to do that? Thomas.li@autodesk.com wrote: > Hi, > I want to convert CString to LPBYTE like > LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring; > is it very dangerous to do that? Depends. What's BYTE, LPBYTE, LPCTSTR, and CString? Ask in an MS newsgroup. That said, in general, you should avoid C-style casts in favor of the new casts (static_cast, reinterpret_cast, dynamic_cast, const_cast). Furthermore, yes, you have a very dangerous conversion, you're casting away a co...

FPGA vs. ARM MCU for floating point operations
Hi - I'm currently using an Atmel AT91SAM7X256 to do a large amount of floating point operations (mostly multiplies with a decent amount of trig as well). It does OK - but my floating point needs are soon going to be expanding (by about twenty-fold) and I'm starting to worry that the SAM7X part just won't have enough horsepower for this. I thought about going with a DSP - but then the idea of using an FPGA hit me. I have very little experience with FPGAs - but would love an excuse to get more experience with them. I really like the idea of them - being able to do many things at on...

Convert string to variable, possible?
Can I convert a string to be a variable? For example: str='var'; (convert str -> variable ?) var=38; Possible? Thanks. "onemilimeter" <onemilimeter@yahoo.com> wrote in message news:eef9b93.-1@webx.raydaftYaTP... > Can I convert a string to be a variable? For example: > > str='var'; > (convert str -> variable ?) > var=38; > > Possible? Thanks. help eval Ken Davis wrote: >> str='var'; >> (convert str -> variable ?) >> var=38; >> >> Possible? Thanks. > > help eval Yes ... you're ...

US-TX-Round Rock: ER Nurse (RN), Current TX liscense as an RN. Previous experie (45355032401)
US-TX-Round Rock: ER Nurse (RN), Current TX liscense as an RN. Previous experie (45355032401) ============================================================================================== Position: ER Nurse (RN) Reference: CAM00015 Location: Round Rock TX Duration: Perm Skills: Current TX liscense as an RN. Previous experience in clinical nursing preferred. Certification in basic cardiopulmonary resuscitation. Computer skills. 2 years of emergency room nursing experience. Scope: ER Nurse is responsible f...

reading file round and round
Hi There, I read out the content from a file like: foreach $line (<$handle>) { print $line; sleep(1); } whixh works well so far. But what I would like is, if the loop gets to eof, it should start over on top again. How can i reset the reading pointer back to the beginning of the file? Thanks, -- roN On Mar 19, 11:43=A0am, cerr <ron.egg...@gmail.com> wrote: > Hi There, > > I read out the content from a file like: > foreach $line (<$handle>) { > =A0 =A0 =A0 =A0 =A0 print $line; > =A0 =A0 =A0 =A0 =A0 sleep(1); > =A0 =A0 ...

Aereo Loses First Round in Copyright Office, While Dish Wins its Next Round in the Ninth Circuit [telecom]
By Herry Cole, CommLawBlog, July 20, 2014 More developments in the realm of Internet retransmission of OTA signals. Aereo - the gift that keeps on giving, at least when it comes to blogworthy content. As we reported, after it got its clock cleaned at the Supreme Court, Aereo bounced back with Plan B, which amounted to declaring itself (a) a cable system and, thus, (b) eligible for the compulsory copyright license granted to cable systems. But you can't just say "I'm a cable system" and expect anybody to believe you. So Aereo went ahead with some of the paperwork re...

To convert SIMULINK to eZdsp
I have executed the necessary procedure in order to obtain SVPWM waveform by using to convert SIMULINK to eZdsp target in the real time workshop mode unfortunately after connecting of inverter output to DC motor, my program have stopped. Could you please let me know what should I do now? Meanwhile, my email addresses are as follows: m_marzband2005@yahoo.com mousa.marzband@estudiant.upc.edu Thank you so much in advance for your attention. Best regards, Mousa Marzband ...

US-TX-Round Rock: RN ICU (PRN), Current Texas RN license. Previous experience i (45352257607)
US-TX-Round Rock: RN ICU (PRN), Current Texas RN license. Previous experience i (45352257607) ============================================================================================== Position: RN ICU (PRN) Reference: CAM00017 Location: Round Rock TX Duration: PRN Skills: Current Texas RN license. Previous experience in clinical nursing. Certification in basic cardiopulmonary resuscitation. Computer skills. Must have critical care nursing experience. PRN. Scope: RN is responsible for professional; n...

how to convert string into number
Hi all, I read several rows of numbers and split each row into an array. I get an array of array. By default Ruby treat each number as a string. I want to convert each string into a number. The only way I can think of is to loop through the old array of array, change each element in each row using #to_f and put them back into a new array. It is not efficient. What other options might be better? Thanks, Li # file format 1 100 33 32 2 500 33 20 .... -- Posted via http://www.ruby-forum.com/. Hi, i would do it like this: array = [] yourfile.each_line{|line| array << line.split...

Rounding to significant figures
Hi all, I need help with rounding down a value to one significant figure. if x = 0.0047; how do i round it down to just x = 0.004; is this possible? if i use round it will bring x = 0. if i use ceil it will bring it to 1. floor will be x = 0 also. num2str(x,1) will bring it 0.005. I'm basically out of functions, please help. and thanks in advance. JP On 3/29/2011 7:24 PM, JP wrote: > Hi all, > > I need help with rounding down a value to one significant figure. > > if x = 0.0047; > > how do i round it down to just x = 0.004; is this possible? > > if i use...

FormatPercent rounds differently on different computers?
I have two machines, and FormatPercent() returns different values on the different machines. I'm using vb6. Machine 1 is an AMD64 laptop with XP sp2. ?formatpercent(.225,0) 23% Machine 2 is an intel pentium 4 desktop with XP, but no sp2 ?formatpercent(.225, 0) 22% Why is one machine rounding up, and the other rounding to even (banker's rounding)? ...

US-TX-Round Rock: SQL Server DBA, Relational DB princeples/practices; (45331432526)
US-TX-Round Rock: SQL Server DBA, Relational DB princeples/practices; (45331432526) =================================================================================== Position: SQL Server DBA Reference: SMC01769 Location: Round Rock TX Duration: Skills: Expert knowledge of relational database principles and practices. Deep experience is required in architecting, and managing large enterprise Oracle and/or Microsoft SQL Server environments. Well versed in Optimizing Databases/database servers, ...

US-TX-Round Rock: Oracle Data Warehouse, Lrg data warehouse exp (4-6 terabytes) (45321157600)
US-TX-Round Rock: Oracle Data Warehouse, Lrg data warehouse exp (4-6 terabytes) (45321157600) ============================================================================================= Position: Oracle Data Warehouse Reference: SMC01639 Location: Round Rock TX Duration: 9M Skills: Large data warehouse experience (4-6 terabytes) Scope: -DBA responsibilities including but not limited to: Ensuring database availability, data integrity, performance/tuning, problem troubleshooting/resolution. -24x7x365 support ...

Matrix convertions
Hi i have the following matrix problem: i read data from a file, and convert it to a Matrix Test = cell2mat(textscan(fid,'%f%f%f%f%f',m*n)); that is no problem so far, but the structure in the file is, that there are lines with 9 values (or better should be)...but in the file is one line with 5 values, and then one with four, and so on. so i get a Matrix, that looks like this: 3 4 5 6 7 1 2 3 4 NaN 3 9 7 5 3 5 6 7 8 NaN but i want to have the 9 column matrix... (this could be mor then 2 lines, 9 values is just an example) so i use for ti=1:linenr, if ti<linenr ...

round() function wrong?
Hi All, i'm running Postgresql 2.2x, so i am not quitse sure wether the bug i am reporting is already fixed in newer versions or not. In my version select round(2.5); returns 2; select round(2.5000001) returns 3; refering to my math professor thats wrong, at least in germany. select round(2.5); should return 3 regards jochen ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org On Wed, 22 Oct 2003, Jochen Westland [invigo] wrote: > Hi All, > i'm running Po...

Peculiar rounding behavior
Immediately after starting Maple 9.03, type: evalf[14](arctan(387.00000001642)); and get: 1.5682123532178 The correct 19 digit value is: 1.5682123532178(50715) Now edit the "14" in the square brackets and execute again: evalf[17](arctan(387.00000001642)); and get: 1.5682123532178507 Now re-edit the [17] back to [14] and execute: evalf[14](arctan(387.00000001642)); and get: 1.5682123532179 What's going on here? Maple forgot how to round until shown what the next 3 digits are? Then it remembered? In article <qkgug097ablnlf24lgvjkb2qkhaj0jaaf...

Re: How to convert hours to minutes in SAS8.2 version for below
Try this: data a; input hours; time=compbl(int(hours)||':'||put((hours-int(hours))*60,z2.)); cards; 0 0.5 1 2 3 ; run; proc print; run; Shaik Hymad <hymadsk@GMAIL.COM> Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> 09/09/2009 07:29 AM Please respond to Shaik Hymad <hymadsk@GMAIL.COM> To SAS-L@LISTSERV.UGA.EDU cc Subject How to convert hours to minutes in SAS8.2 version for below senario HI All, I have data like hours 0 0.5 1 2 3 i need to convert time format like hours time 0 0:00 0.5 0:30 1 1:0...